Skip to content

Fix multiple memory safety issues in stb_image and stb_vorbis#1927

Open
boergeson wants to merge 2 commits into
nothings:masterfrom
boergeson:fix/memory-safety-issues
Open

Fix multiple memory safety issues in stb_image and stb_vorbis#1927
boergeson wants to merge 2 commits into
nothings:masterfrom
boergeson:fix/memory-safety-issues

Conversation

@boergeson

Copy link
Copy Markdown

Fixes for several integer overflow, out-of-bounds, and logic bugs found during a security review.

stb_image.h:

  • Add overflow checks to stbi__convert_16_to_8 and stbi__convert_8_to_16 (lines 1193, 1209)
  • Use stbi__malloc_mad4 in stbi__convert_format16 -- the 8-bit sibling was already using stbi__malloc_mad3 but the 16-bit version was missed (line 1820)
  • Fix two_back pointer in animated GIF loader: out - 2*stride points before the buffer, should be out + (layers-2)*stride (line 7023). Crashes under ASAN.
  • Validate palette index in stbi__expand_png_palette -- the palette length was being ignored via STBI_NOTUSED(len), allowing out-of-bounds reads from uninitialized stack memory (line 4988)
  • Fix stbi__process_marker failure returning 1 (success) instead of 0 (line 3448)

stb_vorbis.c:

  • Fix sign error in bounds clamp in codebook_decode_deinterleave_repeat: - c_inter should be + c_inter (line 1891)

PoCs and a full writeup are in the poc/ directory on this branch. See the companion issue for the complete list of findings.

stb_image.h:
- Add overflow checks to stbi__convert_16_to_8 and stbi__convert_8_to_16
- Use stbi__malloc_mad4 in stbi__convert_format16 (8-bit sibling already used stbi__malloc_mad3)
- Fix two_back pointer in animated GIF loader (was out - 2*stride, should be out + (layers-2)*stride)
- Validate palette index against palette length in stbi__expand_png_palette
- Fix stbi__process_marker failure returning success instead of failure

stb_vorbis.c:
- Fix sign error in bounds clamp in codebook_decode_deinterleave_repeat
@AliceLR

AliceLR commented Jun 3, 2026

Copy link
Copy Markdown

The stb_vorbis.c change is a duplicate of #1490.

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