Skip to content

Fix HEIF/AVIF output buffer overflow - #448

Open
gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/harden-heif-avif-output-writer
Open

Fix HEIF/AVIF output buffer overflow#448
gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/harden-heif-avif-output-writer

Conversation

@gregbenz

Copy link
Copy Markdown
Contributor

What changed

  • Make the libheif memory writer reject size overflow and allocation failure.
  • Propagate errors returned by heif_context_write().
  • Reject encoded output larger than the caller's destination capacity before copying it.
  • Preserve the destination's capacity and add HEIF/AVIF regression tests.

Why

The HEIF and AVIF encoders copied the complete encoded file into the destination without checking its capacity. An undersized destination could therefore be overwritten while the encoder reported success. The encoder now returns UHDR_CODEC_MEM_ERROR without modifying the destination buffer.

Testing

  • Both regressions fail on current main: capacity 1 accepts and copies 15,245 bytes for HEIF and 2,323 bytes for AVIF.
  • Both regressions pass with this fix.
  • Full HEIF-enabled unit suite: 1,072 passed, 224 skipped, 0 failed.
  • Both modified codec translation units compile with -fno-exceptions and warnings as errors.

@google-cla

google-cla Bot commented Aug 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gregbenz

Copy link
Copy Markdown
Contributor Author

@DichenZhang1 FYI that this was flagged by the google-cla check, which is pretty odd as I've done that, contributed, and other PRs sent yesterday were not flagged. Not sure why this one was, but seems incorrectly flagged by that bot. Perhaps that automatic build was a factor? It appears to have been a transient build/test issue (Error: socket hang up)

@gregbenz
gregbenz force-pushed the codex/harden-heif-avif-output-writer branch from 869af7a to 3b7da0b Compare August 15, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants