Skip to content

Commit

Permalink
More careful handling in APNG decoder (for APNG) (#3697)
Browse files Browse the repository at this point in the history
(cherry picked from commit 58ce689b89b80a2502618299ceee49e580be0e54)
  • Loading branch information
eustas committed Dec 5, 2024
1 parent 7ea4104 commit dc31aeb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions third_party/apngdis/dec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "lib/base/compiler_specific.h"
#include "lib/base/printf_macros.h"
#include "lib/base/rect.h"
#include "lib/base/sanitizers.h"
#include "lib/base/span.h"
#include "lib/base/status.h"
#include "lib/extras/codestream_header.h"
Expand Down Expand Up @@ -623,13 +624,15 @@ struct Context {
png_process_data(png_ptr, info_ptr, const_cast<uint8_t*>(kFooter.data()),
kFooter.size());
// before destroying: check if we encountered any metadata chunks
png_textp text_ptr;
int num_text;
png_get_text(png_ptr, info_ptr, &text_ptr, &num_text);
for (int i = 0; i < num_text; i++) {
Status result = DecodeBlob(text_ptr[i], metadata);
// Ignore unknown / malformed blob.
(void)result;
png_textp text_ptr = nullptr;
int num_text = 0;
if (png_get_text(png_ptr, info_ptr, &text_ptr, &num_text) != 0) {
msan::UnpoisonMemory(text_ptr, sizeof(png_text_struct) * num_text);
for (int i = 0; i < num_text; i++) {
Status result = DecodeBlob(text_ptr[i], metadata);
// Ignore unknown / malformed blob.
(void)result;
}
}

return true;
Expand Down

0 comments on commit dc31aeb

Please sign in to comment.