Skip to content

Commit

Permalink
Don't abort in the destructor of allotment if allocation failed (libj…
Browse files Browse the repository at this point in the history
…xl#3835)

Co-authored-by: Sami Boukortt <sboukortt@google.com>
(cherry picked from commit 8f22cb1)
  • Loading branch information
mo271 committed Nov 26, 2024
1 parent d2159fe commit 7c621cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/jxl/enc_bit_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ Status BitWriter::Allotment::Init(BitWriter* JXL_RESTRICT writer) {
prev_bits_written_ = writer->BitsWritten();
const size_t prev_bytes = writer->storage_.size();
const size_t next_bytes = DivCeil(max_bits_, kBitsPerByte);
JXL_RETURN_IF_ERROR(writer->storage_.resize(prev_bytes + next_bytes));
if (!writer->storage_.resize(prev_bytes + next_bytes)) {
called_ = true;
return false;
}
parent_ = writer->current_allotment_;
writer->current_allotment_ = this;
return true;
Expand Down
4 changes: 2 additions & 2 deletions tools/streaming_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Status Run(const FuzzSpec& spec, TrackingMemoryManager& memory_manager) {
std::vector<uint8_t> enc_streaming;

const auto encode = [&]() -> Status {
// It is not clear, which approach eatc more memory.
// It is not clear, which approach eats more memory.
JXL_ASSIGN_OR_RETURN(enc_default, Encode(spec, memory_manager, false));
Check(memory_manager.Reset());
JXL_ASSIGN_OR_RETURN(enc_streaming, Encode(spec, memory_manager, true));
Expand All @@ -320,7 +320,7 @@ Status Run(const FuzzSpec& spec, TrackingMemoryManager& memory_manager) {
// It is fine, if encoder OOMs.
if (!encode()) return true;

// It is NOT OK, it decoder OOMs - it should not consume more than encoder.
// It is NOT OK, if decoder OOMs - it should not consume more than encoder.
JXL_ASSIGN_OR_RETURN(auto dec_default, Decode(enc_default, memory_manager));
Check(memory_manager.Reset());
JXL_ASSIGN_OR_RETURN(auto dec_streaming,
Expand Down

0 comments on commit 7c621cd

Please sign in to comment.