|
| 1 | +From 8c26ee46da1cca4559c8b9da023c06ab5a2fb2c8 Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark < [email protected]> |
| 3 | +Date: Mon, 27 Oct 2025 18:38:03 +0000 |
| 4 | +Subject: [PATCH] fix(null): improve error handlings when passing a null |
| 5 | + pointer to some functions from lz4frame |
| 6 | + |
| 7 | +- LZ4F_createCDict_advanced: guard null dictBuffer and proper allocation check |
| 8 | +- LZ4F_getFrameInfo: validate input pointers before use |
| 9 | +- frametest: adjust cdict creation order and null check (not present in this tree) |
| 10 | + |
| 11 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 12 | +Upstream-reference: AI Backport of https://github.com/lz4/lz4/pull/1593.patch |
| 13 | +--- |
| 14 | + extra/lz4/lz4-1.10.0/lib/lz4frame.c | 16 ++++++++++++++-- |
| 15 | + 1 file changed, 14 insertions(+), 2 deletions(-) |
| 16 | + |
| 17 | +diff --git a/extra/lz4/lz4-1.10.0/lib/lz4frame.c b/extra/lz4/lz4-1.10.0/lib/lz4frame.c |
| 18 | +index f89c055..a00b31a 100644 |
| 19 | +--- a/extra/lz4/lz4-1.10.0/lib/lz4frame.c |
| 20 | ++++ b/extra/lz4/lz4-1.10.0/lib/lz4frame.c |
| 21 | +@@ -539,9 +539,15 @@ LZ4F_CDict* |
| 22 | + LZ4F_createCDict_advanced(LZ4F_CustomMem cmem, const void* dictBuffer, size_t dictSize) |
| 23 | + { |
| 24 | + const char* dictStart = (const char*)dictBuffer; |
| 25 | +- LZ4F_CDict* const cdict = (LZ4F_CDict*)LZ4F_malloc(sizeof(*cdict), cmem); |
| 26 | ++ LZ4F_CDict* cdict = NULL; |
| 27 | ++ |
| 28 | + DEBUGLOG(4, "LZ4F_createCDict_advanced"); |
| 29 | +- if (!cdict) return NULL; |
| 30 | ++ |
| 31 | ++ if (!dictStart) |
| 32 | ++ return NULL; |
| 33 | ++ cdict = (LZ4F_CDict*)LZ4F_malloc(sizeof(*cdict), cmem); |
| 34 | ++ if (!cdict) |
| 35 | ++ return NULL; |
| 36 | + cdict->cmem = cmem; |
| 37 | + if (dictSize > 64 KB) { |
| 38 | + dictStart += dictSize - 64 KB; |
| 39 | +@@ -1480,12 +1486,18 @@ size_t LZ4F_headerSize(const void* src, size_t srcSize) |
| 40 | + * @return : an hint about how many srcSize bytes LZ4F_decompress() expects for next call, |
| 41 | + * or an error code which can be tested using LZ4F_isError() |
| 42 | + * note 1 : in case of error, dctx is not modified. Decoding operations can resume from where they stopped. |
| 43 | ++ |
| 44 | + * note 2 : frame parameters are *copied into* an already allocated LZ4F_frameInfo_t structure. |
| 45 | + */ |
| 46 | + LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_dctx* dctx, |
| 47 | + LZ4F_frameInfo_t* frameInfoPtr, |
| 48 | + const void* srcBuffer, size_t* srcSizePtr) |
| 49 | + { |
| 50 | ++ assert(dctx != NULL); |
| 51 | ++ RETURN_ERROR_IF(frameInfoPtr == NULL, parameter_null); |
| 52 | ++ RETURN_ERROR_IF(srcSizePtr == NULL, parameter_null); |
| 53 | ++ |
| 54 | ++ |
| 55 | + LZ4F_STATIC_ASSERT(dstage_getFrameHeader < dstage_storeFrameHeader); |
| 56 | + if (dctx->dStage > dstage_storeFrameHeader) { |
| 57 | + /* frameInfo already decoded */ |
| 58 | +-- |
| 59 | +2.45.4 |
| 60 | + |
0 commit comments