|
| 1 | +From 6c8135e4bae6c1a4f1e20019159f596ee2e8ae2a Mon Sep 17 00:00:00 2001 |
| 2 | +From: louislafosse < [email protected]> |
| 3 | +Date: Mon, 31 Mar 2025 20:48:52 +0200 |
| 4 | +Subject: [PATCH] fix(null) : improve error handlings when passing a null |
| 5 | + pointer to some functions from lz4frame |
| 6 | + |
| 7 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 8 | +Upstream-reference: https://github.com/lz4/lz4/pull/1593.patch |
| 9 | +--- |
| 10 | + lib/lz4frame.c | 15 +++++++++++++-- |
| 11 | + tests/frametest.c | 9 ++++++--- |
| 12 | + 2 files changed, 19 insertions(+), 5 deletions(-) |
| 13 | + |
| 14 | +diff --git a/lib/lz4frame.c b/lib/lz4frame.c |
| 15 | +index 174f9ae..cc6ed6f 100644 |
| 16 | +--- a/lib/lz4frame.c |
| 17 | ++++ b/lib/lz4frame.c |
| 18 | +@@ -530,9 +530,16 @@ LZ4F_CDict* |
| 19 | + LZ4F_createCDict_advanced(LZ4F_CustomMem cmem, const void* dictBuffer, size_t dictSize) |
| 20 | + { |
| 21 | + const char* dictStart = (const char*)dictBuffer; |
| 22 | +- LZ4F_CDict* const cdict = (LZ4F_CDict*)LZ4F_malloc(sizeof(*cdict), cmem); |
| 23 | ++ LZ4F_CDict* cdict = NULL; |
| 24 | ++ |
| 25 | + DEBUGLOG(4, "LZ4F_createCDict_advanced"); |
| 26 | +- if (!cdict) return NULL; |
| 27 | ++ |
| 28 | ++ if (!dictStart) |
| 29 | ++ return NULL; |
| 30 | ++ cdict = (LZ4F_CDict*)LZ4F_malloc(sizeof(*cdict), cmem); |
| 31 | ++ if (!cdict) |
| 32 | ++ return NULL; |
| 33 | ++ |
| 34 | + cdict->cmem = cmem; |
| 35 | + if (dictSize > 64 KB) { |
| 36 | + dictStart += dictSize - 64 KB; |
| 37 | +@@ -1429,6 +1436,10 @@ LZ4F_errorCode_t LZ4F_getFrameInfo(LZ4F_dctx* dctx, |
| 38 | + LZ4F_frameInfo_t* frameInfoPtr, |
| 39 | + const void* srcBuffer, size_t* srcSizePtr) |
| 40 | + { |
| 41 | ++ assert(dctx != NULL); |
| 42 | ++ RETURN_ERROR_IF(frameInfoPtr == NULL, parameter_null); |
| 43 | ++ RETURN_ERROR_IF(srcSizePtr == NULL, parameter_null); |
| 44 | ++ |
| 45 | + LZ4F_STATIC_ASSERT(dstage_getFrameHeader < dstage_storeFrameHeader); |
| 46 | + if (dctx->dStage > dstage_storeFrameHeader) { |
| 47 | + /* frameInfo already decoded */ |
| 48 | +diff --git a/tests/frametest.c b/tests/frametest.c |
| 49 | +index 3301955..523e35d 100644 |
| 50 | +--- a/tests/frametest.c |
| 51 | ++++ b/tests/frametest.c |
| 52 | +@@ -589,10 +589,13 @@ int basicTests(U32 seed, double compressibility) |
| 53 | + size_t const srcSize = 65 KB; /* must be > 64 KB to avoid short-size optimizations */ |
| 54 | + size_t const dstCapacity = LZ4F_compressFrameBound(srcSize, NULL); |
| 55 | + size_t cSizeNoDict, cSizeWithDict; |
| 56 | +- LZ4F_CDict* const cdict = LZ4F_createCDict(CNBuffer, dictSize); |
| 57 | +- if (cdict == NULL) goto _output_error; |
| 58 | +- CHECK( LZ4F_createCompressionContext(&cctx, LZ4F_VERSION) ); |
| 59 | ++ LZ4F_CDict* cdict = NULL; |
| 60 | + |
| 61 | ++ CHECK( LZ4F_createCompressionContext(&cctx, LZ4F_VERSION) ); |
| 62 | ++ cdict = LZ4F_createCDict(CNBuffer, dictSize); |
| 63 | ++ if (cdict == NULL) |
| 64 | ++ goto _output_error; |
| 65 | ++ |
| 66 | + DISPLAYLEVEL(3, "Testing LZ4F_createCDict_advanced : "); |
| 67 | + { LZ4F_CDict* const cda = LZ4F_createCDict_advanced(lz4f_cmem_test, CNBuffer, dictSize); |
| 68 | + if (cda == NULL) goto _output_error; |
| 69 | +-- |
| 70 | +2.45.4 |
| 71 | + |
0 commit comments