mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 17:31:47 +09:00
Issue #1288 - Part 2: Add a partial LZ4 decompression routine.
This function never writes beyond `aDest` + `aMaxOutputSize`, and is therefore protexted against malicious datapackets. It also ignores unconsumed input upon reaching `aMaxOutputSize` and can therefore be used for parial decompression of LZ4 input up to a desired resulting size of decompressed data.
This commit is contained in:
parent
0d109e3c9f
commit
da2e08390c
2 changed files with 44 additions and 0 deletions
|
|
@ -76,3 +76,24 @@ LZ4::decompress(const char* aSource, size_t aInputSize, char* aDest,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
LZ4::decompressPartial(const char* aSource, size_t aInputSize, char* aDest,
|
||||
size_t aMaxOutputSize, size_t* aOutputSize)
|
||||
{
|
||||
CheckedInt<int> maxOutputSizeChecked = aMaxOutputSize;
|
||||
MOZ_ASSERT(maxOutputSizeChecked.isValid());
|
||||
CheckedInt<int> inputSizeChecked = aInputSize;
|
||||
MOZ_ASSERT(inputSizeChecked.isValid());
|
||||
|
||||
int ret = LZ4_decompress_safe_partial(aSource, aDest,
|
||||
inputSizeChecked.value(),
|
||||
maxOutputSizeChecked.value(),
|
||||
maxOutputSizeChecked.value());
|
||||
if (ret >= 0) {
|
||||
*aOutputSize = ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
*aOutputSize = 0;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue