]> git.ipfire.org Git - thirdparty/zstd.git/commit
new method to deal with offset==0
authorYann Collet <cyan@fb.com>
Fri, 8 Mar 2024 22:55:38 +0000 (14:55 -0800)
committerYann Collet <cyan@fb.com>
Fri, 8 Mar 2024 23:26:06 +0000 (15:26 -0800)
commita9fb8d4c41bf3cc829adf20aea3768863d03cd0d
tree5c874b13f9c253da73e08aedcd1af0d5963dd120
parente127139ceb60065917c43ab01634aa9563ec46a4
new method to deal with offset==0

in this new method, when an `offset==0` is detected,
it's converted into (size_t)(-1), instead of 1.

The logic is that (size_t)(-1) is effectively an extremely large positive number,
which will not pass the offset distance test at next stage (`execSequence()`).
Checked the source code, and offset is always checked (as it should),
using a formula which is not vulnerable to arithmetic overflow:
```
RETURN_ERROR_IF(sequence.offset > (size_t)(oLitEnd - virtualStart),
```

The benefit is that such a case (offset==0) is always detected as corrupted data
as opposed to relying on the checksum to detect the error.
lib/decompress/zstd_decompress_block.c