Skip to content

Prevent panic on invalid palette indices - #180

Draft
jesposito wants to merge 1 commit into
disintegration:masterfrom
jesposito:agent/prevent-invalid-palette-panic
Draft

Prevent panic on invalid palette indices#180
jesposito wants to merge 1 commit into
disintegration:masterfrom
jesposito:agent/prevent-invalid-palette-panic

Conversation

@jesposito

Copy link
Copy Markdown

Summary

  • bounds-check paletted-image pixel values before indexing the scanner palette
  • treat invalid palette entries as transparent black instead of panicking
  • add a focused regression test for a malformed image.Paletted

Why

scanner.scan currently assumes that every byte in image.Paletted.Pix is a valid index into the image palette. A malformed image can violate that invariant and trigger an index-out-of-range panic. This is the crash reported in #165 and CVE-2023-36308.

Newer golang.org/x/image/tiff versions reject the published malformed TIFF during decoding, but imaging can still receive an invalid paletted image from callers or older decoders. The defensive check makes the scanner safe independently of the decoder version and keeps compatibility with the existing no-error scanner API.

Fixes #165.

Related upstream parser fix: golang/go#67624

Compatibility

This is an internal behavior change with no API changes and remains compatible with the Go versions in the existing Travis matrix.

Validation

  • regression test panics on current master and passes with this patch
  • go test -race ./...

dabao1955 pushed a commit to NekoSekaiMoe/imaging that referenced this pull request Jul 26, 2026
…ation

- fix: prevent panic on invalid paletted image indices (PR disintegration#180)
- refactor: replace deprecated io/ioutil with io and os packages (PR disintegration#175)
- perf: use unbuffered channel in parallel processing (PR disintegration#162)
- fix: update example import path to NekoSekaiMoe

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant