Re: [PATCH v2 12/15] lib/lz4: widen LZ4_DECOMPRESS_INPLACE_MARGIN for the fast decode loop
From: Michal Wilczynski
Date: Thu Nov 12 2026 - 07:43:55 EST
On 11/11/26 23:02, Gao Xiang wrote:
> Hi Michal,
>
> On Fri, Nov 06, 2026 at 03:42:52PM +0100, Michal Wilczynski wrote:
>> erofs decompresses a pcluster in place when the slack after the output
>> is at least LZ4_DECOMPRESS_INPLACE_MARGIN(compressed size), upstream's
>> (compressedSize >> 8) + 32.
>>
>> That holds for the fork, which overshoots its output by at most 8
>> bytes. Upstream's LZ4_FAST_DEC_LOOP, which the next patch brings in for
>> x86 and arm64, copies in 32-byte steps and can overwrite input it has
>> not read yet: of 172410 valid streams laid out as erofs does at exactly
>> that margin, 3660 fail to decode, none with the fork. The worst needs
>> (compressedSize >> 8) + 33. Images mkfs.erofs built did not hit this,
>> but nothing in the format rules it out.
>>
>> Use (compressedSize >> 8) + (compressedSize >> 15) + 36, which takes a
>> 4K pcluster's margin from 48 to 52 bytes. Upstream's lz4.h defines the
>> macro too, so undefine it first.
>>
>> Signed-off-by: Michal Wilczynski <m.wilczynski@xxxxxxxxxxx>
>
> First, I really think kernel LZ4 should be updated for many years, so
> thanks for this!
>
> But my personal thought is that could you just fold this patch into
> the next one ("lib/lz4: switch the decompressor to the vendored sources")?
> Because this one should be part of the fast loop update.
>
> Although the current patch order is also fine, but my potential concern
> is that people don't know the details maybe pick the random ones for
> backporting, which is what I'd like to avoid so I hope this patch could
> be just part of it, otherwise the inplace decompression could be broken.
>
Make sense I'll fold it into the decompressor switch in v3 so the
wider margin and the fast loop can't be picked up separately.
Thanks for the review and the kind words
Best regards,
--
Michal Wilczynski <m.wilczynski@xxxxxxxxxxx>