Re: [PATCH RFC 1/9] lib/lz4: import upstream LZ4 sources verbatim
From: Michal Wilczynski
Date: Sat Oct 03 2026 - 19:51:15 EST
On 9/28/26 07:19, Sergey Senozhatsky wrote:
> On (26/09/25 13:27), Michal Wilczynski wrote:
> [..]
>> +int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
>> +{
>> + LZ4_stream_t_internal* const ctx = & LZ4_initStream(state, sizeof(LZ4_stream_t)) -> internal_donotuse;
>> + assert(ctx != NULL);
>
> Probably in some other places as well:
>
> LZ4_initStream() can return NULL, but the code immediately derefs
> the pointer. The assert() check seems to be misplaced, unless I'm
> missing something.
>
> I suppose those need to be decoupled. First LZ4_initStream() call and
> NULL check, then stream->internal_donotuse.
Good catch, this assert() is a noop in the kernel (as any build without
LZ4_DEBUG), so a NULL, undersized or misaligned wrkmem oopses in
LZ4_compress_fast(), and LZ4_compress_destSize() and LZ4_resetStreamHC()
carry on with an uninitialised state.
No in-tree caller hits it (all use kmalloc/vmalloc), and I listed the
alignment requirement as a behaviour change in the cover letter. Still,
the vendored files need to stay verbatim.
So in v2 our own entry points can check alignment with a WARN_ON_ONCE()
and bail out early. It might be something that we can fix upstream as
well.
>
Best regards,
--
Michal Wilczynski <m.wilczynski@xxxxxxxxxxx>