fix memory leak when reading damaged PIZ files
@@ -256,14 +256,29 @@ FastHufDecoder::FastHufDecoder
int symbol = *i >> 6;
if (mapping[codeLen] >= static_cast<Int64>(_numSymbols))
+ {
+ delete[] _idToSymbol;
+ _idToSymbol = NULL;
throw IEX_NAMESPACE::InputExc ("Huffman decode error "
"(Invalid symbol in header).");
-
+ }
_idToSymbol[mapping[codeLen]] = symbol;
mapping[codeLen]++;
}
+ //
+ // exceptions can be thrown whilst building tables. Delete
+ // _idToSynmbol before re-throwing to prevent memory leak
+ //
+ try
+ {
buildTables(base, offset);
+ }catch(...)
+ {
+ delete[] _idToSymbol;
+ _idToSymbol = NULL;
+ throw;
+ }
}
