From 91cc4e377f23e4de0ac874809ee1cdea58b29879 Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 4 Apr 2022 10:44:06 -0700 Subject: [PATCH] BackwardReferencesHashChainDistanceOnly: fix segfault on OOM change CostManager to calloc to avoid frees on undefined pointer values in CostManagerClear() should the cost_model allocation succeed, but the cost_manager allocation fail since: v0.5.0-93-g3e023c17 Speed-up BackwardReferencesHashChainDistanceOnly. Tested: for i in `seq 1 639`; do export MALLOC_FAIL_AT=$i ./examples/cwebp -m 6 -q 100 -lossless jpeg_file done Bug: webp:565 Change-Id: I376d81e6f41eb73529053e9e30c142b4b4f6b45b (cherry picked from commit a828a59b49d2e3fbc40dc42a6ee6426cd0f2c9dc) (cherry picked from commit dd80bb43431c222762be47fd92f8a37e032bc2c0) (cherry picked from commit 4d0964cd0c2b20668d77f965a7e2fbe0b7dcaea4) --- src/enc/backward_references_cost_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/enc/backward_references_cost_enc.c b/src/enc/backward_references_cost_enc.c index 7175496c..ae8d5c4f 100644 --- a/src/enc/backward_references_cost_enc.c +++ b/src/enc/backward_references_cost_enc.c @@ -577,7 +577,7 @@ static int BackwardReferencesHashChainDistanceOnly( (CostModel*)WebPSafeCalloc(1ULL, cost_model_size); VP8LColorCache hashers; CostManager* cost_manager = - (CostManager*)WebPSafeMalloc(1ULL, sizeof(*cost_manager)); + (CostManager*)WebPSafeCalloc(1ULL, sizeof(*cost_manager)); int offset_prev = -1, len_prev = -1; double offset_cost = -1; int first_offset_is_constant = -1; // initialized with 'impossible' value