Merge changes Id9890a60,I376d81e6,I1c958838 into main

* changes:
  GetBackwardReferences: fail on alloc error
  BackwardReferencesHashChainDistanceOnly: fix segfault on OOM
  VP8LEncodeStream: fix segfault on OOM
This commit is contained in:
James Zern 2022-04-06 20:04:25 +00:00 committed by Gerrit Code Review
commit 2de4b05a56
3 changed files with 19 additions and 13 deletions

View File

@ -577,7 +577,7 @@ static int BackwardReferencesHashChainDistanceOnly(
(CostModel*)WebPSafeCalloc(1ULL, cost_model_size); (CostModel*)WebPSafeCalloc(1ULL, cost_model_size);
VP8LColorCache hashers; VP8LColorCache hashers;
CostManager* cost_manager = CostManager* cost_manager =
(CostManager*)WebPSafeMalloc(1ULL, sizeof(*cost_manager)); (CostManager*)WebPSafeCalloc(1ULL, sizeof(*cost_manager));
int offset_prev = -1, len_prev = -1; int offset_prev = -1, len_prev = -1;
double offset_cost = -1; double offset_cost = -1;
int first_offset_is_constant = -1; // initialized with 'impossible' value int first_offset_is_constant = -1; // initialized with 'impossible' value

View File

@ -1007,15 +1007,16 @@ static int GetBackwardReferences(int width, int height,
const VP8LHashChain* const hash_chain_tmp = const VP8LHashChain* const hash_chain_tmp =
(lz77_types_best[i] == kLZ77Standard) ? hash_chain : &hash_chain_box; (lz77_types_best[i] == kLZ77Standard) ? hash_chain : &hash_chain_box;
const int cache_bits = (i == 1) ? 0 : *cache_bits_best; const int cache_bits = (i == 1) ? 0 : *cache_bits_best;
if (VP8LBackwardReferencesTraceBackwards(width, height, argb, cache_bits, double bit_cost_trace;
hash_chain_tmp, &refs[i], if (!VP8LBackwardReferencesTraceBackwards(width, height, argb, cache_bits,
refs_tmp)) { hash_chain_tmp, &refs[i],
double bit_cost_trace; refs_tmp)) {
VP8LHistogramCreate(histo, refs_tmp, cache_bits); goto Error;
bit_cost_trace = VP8LHistogramEstimateBits(histo); }
if (bit_cost_trace < bit_costs_best[i]) { VP8LHistogramCreate(histo, refs_tmp, cache_bits);
BackwardRefsSwap(refs_tmp, &refs[i]); bit_cost_trace = VP8LHistogramEstimateBits(histo);
} if (bit_cost_trace < bit_costs_best[i]) {
BackwardRefsSwap(refs_tmp, &refs[i]);
} }
} }

View File

@ -1966,14 +1966,19 @@ int VP8LEncodeStream(const WebPConfig* const config,
const WebPWorkerInterface* const worker_interface = WebPGetWorkerInterface(); const WebPWorkerInterface* const worker_interface = WebPGetWorkerInterface();
int ok_main; int ok_main;
if (enc_main == NULL || !VP8LBitWriterInit(&bw_side, 0)) {
WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
VP8LEncoderDelete(enc_main);
return 0;
}
// Avoid "garbage value" error from Clang's static analysis tool. // Avoid "garbage value" error from Clang's static analysis tool.
WebPPictureInit(&picture_side); WebPPictureInit(&picture_side);
// Analyze image (entropy, num_palettes etc) // Analyze image (entropy, num_palettes etc)
if (enc_main == NULL || if (!EncoderAnalyze(enc_main, crunch_configs, &num_crunch_configs_main,
!EncoderAnalyze(enc_main, crunch_configs, &num_crunch_configs_main,
&red_and_blue_always_zero) || &red_and_blue_always_zero) ||
!EncoderInit(enc_main) || !VP8LBitWriterInit(&bw_side, 0)) { !EncoderInit(enc_main)) {
WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY); WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
goto Error; goto Error;
} }