Repository navigation
fix: reject corrupt JPEG Huffman data, bound coefficient math and fix two data races - #1357
Open
giuliowaitforitdavide wants to merge 3 commits into
Open
giuliowaitforitdavide wants to merge 3 commits into
giuliowaitforitdavide wants to merge 3 commits into
Conversation
Fuzzing the image decoder under UBSan found undefined behavior on corrupt JPEGs, with identical output for valid files: - Start every Huffman table with no codes, and reject oversubscribed tables when they are built. Both made the slow decode path compute a negative index into the symbol table. - Reject bit reads longer than 16 bits. A malformed table could ask for up to 255 bits and shift past the width of an int. - Keep coefficients and the DC predictor 16-bit, as libjpeg and the progressive path do, and run the IDCT on 64-bit intermediates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ds4_tp_big_gate_exchange initialized two function statics on first use without synchronization, which ThreadSanitizer reports when two ranks share a process, as in the transport tests. The arrival grace also took its floor from whichever tp called first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The main thread writes the stop flag while the keepalive thread polls it. volatile does not make that access race-free; use the __atomic builtins the file already uses elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
giuliowaitforitdavide
force-pushed
the
fix/decoder-and-race-findings
branch
from
November 17, 2026 12:05
069aa5a to
4c7ff68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1356
Fixes items 2-6 of #1356: undefined behavior in the JPEG decoder on corrupt
input, and two data races. Item 1, the out-of-bounds luma read, is left to
#1112.
Changes
third_party/iris/jpeg.h:file never defines fails to decode instead of indexing
values[-1].check libjpeg makes.
jpeg_get_bitsrejects reads longer than 16 bits, the most JPEG ever codes.JCOEFandthis decoder's progressive path already do, and the IDCT uses 64-bit
intermediates, like libjpeg's
JLONG.ds4_tp.c:ds4_tp_big_gate_exchangereadsDS4_TP_BIG_GATE_DEBUGandDS4_TP_BIG_GATE_ARRIVAL_MSon each call instead of caching them in functionstatics. The arrival floor now comes from the calling
tp's own gate timeout.ds4_metal.m: the queue keepalive stop flag uses__atomicloads and storesinstead of
volatile.tests/test_image_decode.c: four JPEGs built in memory cover an oversubscribedtable, an undefined table, a DC category of 17 and extreme coefficients with
16-bit quantizers.
Testing
On an M3 Max (macOS, Metal) and in Ubuntu 26.04 containers (arm64, and x86-64
under Rosetta):
tests/test_image_decode: passes. Onmain, three of the new checks fail;the extreme-coefficient check fails only under UBSan.
mainon 309 valid JPEG and PNGfiles: Pillow-generated baseline and progressive images at several
qualities and subsamplings, plus the repository fixtures.
makeon macOS,make cpuon Linux.test_tp_commandsandtest_tp_tcp(macOSand Linux), or in
test-qwen4-ssd-expertsandtest-qwen4-resident-arithmetic(macOS).ds4_image_decode_memorywith these fixes and thejpeg.hchange from Upsample a subsampled JPEG luma plane instead of reading past it #1112: eight minutes under ASan and under UBSan found nothing.
No model was used. Distributed inference over a real network, CUDA and ROCm
were not run; the
ds4_tp.cchange only affects how the arrival timeout iscomputed.
Conflicts
tests/test_image_decode.cconflicts with #1348, #1112, #1113 and #1110, whichalso add checks to that file. The conflict is only where the new functions and
the
main()calls go.jpeg.hmerges cleanly with #1112, #1113 and #1110.🤖 Generated with Claude Code