Repository navigation
feat(video): scaffold @dcmjs-org/video with the JPEG and MP4 header parsers - #576
Merged
Merged
Conversation
The package shell for the video wave: name, entry point, MIT license, repository directory, and the @dcmjs-org/core workspace dependency. The image-module index exports only the header parsers for now; the dataset builder joins it in the next slice. Co-Authored-By: Claude Fable 5 <[email protected]>
Verbatim from v2.0-development: src/image/jpegInfo.js (SOF geometry and the JPEG transfer syntax mapping), src/image/mp4Info.js (the ISO BMFF box walk over a random-access reader), the makeTinyMp4 synthesized-fixture helper, and the ported mp4Info suite. Only the test import paths moved with the files; no behavior changed in this commit — review findings 9 and 15 are fixed on top, each with its regression observed red first. Co-Authored-By: Claude Fable 5 <[email protected]>
Review finding 9 (HIGH): the marker-walk guard only required four readable bytes, but the SOF fields span bytes[offset+4 .. offset+9]. Out-of-range reads coerce to 0 in the bitwise math, so the review map's vector — a 480x640 JPEG cut one byte into the width field — returned columns 512 instead of throwing, and a file cut right after the length field returned rows 0, columns 0. The reader now validates that the declared SOF segment fits inside the input (and is at least 8 bytes) before reading any field. The new jpegInfo suite is hand-written (v2 carried no suite for this file): the exact review vector, the cut-after-length shape, and valid SOF0/SOF1/SOF2/SOF3 paths. Both finding tests were observed red against the ported-unfixed reader before this fix. Co-Authored-By: Claude Fable 5 <[email protected]>
Review finding 15 (MED): the stts fallback loop trusted the raw uint32 entry_count. With stsz sample_count 0 and stts entry_count 0x00FFFFFF the parser spun 16.7 million iterations over zero-coerced reads past the box and fabricated numberOfFrames/frameRate from unrelated moov bytes; at 0xFFFFFFFF that is roughly 40 seconds of blocked thread. The loop now requires 16 + entryCount * 8 to fit inside the stts box and throws on the mismatch. The regression corrupts a synthesized MP4 exactly that way and asserts the parse rejects in under two seconds — observed red (the unfixed parser resolved with fabricated values) before this fix. Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Oct 2, 2026
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.
This scaffolds
@dcmjs-org/videoand ports the JPEG and MP4 header parsers, fixing review findings 9 and 15 inside the port. The two parsers are the codec-free front door of the video story:parseJpegInforeads the SOF segment to recover Rows/Columns/BitsAllocated/SamplesPerPixel and the matching JPEG transfer syntax, andparseMp4Infowalks the ISO BMFF box structure — against a random-access reader, so a 20 GB file costs a few 16-byte header probes plus one moov read — to recover geometry, frame count, frame rate, and the H.264 transfer syntax. Neither decodes a pixel; the whole point is that the compressed stream travels into encapsulated PixelData verbatim.On provenance: the package scaffold (package.json, the two index files) is hand-written;
jpegInfo.js,mp4Info.js, themakeTinyMp4synthesized-fixture helper, and the mp4Info suite are verbatim ports from the v2 branch, isolated in their own commit with only the import paths moved. On top of that sit the two finding fixes, each with its regression observed red against the ported-unfixed code first:bytes[offset+4 .. offset+9], and out-of-range reads coerce to 0 in the bitwise math. The review map's vector —FF D8 FF C0 00 11 08 01 E0 02, a 480×640 JPEG cut one byte into the width field — returnedcolumns: 512instead of throwing, and a file cut right after the length field returnedrows: 0, columns: 0. The reader now validates that the declared SOF segment fits inside the input before reading any field. v2 shipped no jpegInfo suite at all, so the newjpegInfo.test.jsis hand-written: the exact review vector, the cut-after-length shape, and happy paths for SOF0/SOF1/SOF2/SOF3. Both truncation tests failed ("Received function did not throw") before the fix.entry_count. Withstsz sample_count = 0andstts entry_count = 0x00FFFFFFthe parser spun 16.7 million iterations over zero-coerced reads past the box and fabricatednumberOfFrames/frameRatefrom unrelated moov bytes — at0xFFFFFFFF, roughly 40 seconds of blocked thread. The loop now requires16 + entryCount * 8to fit inside the stts box and throws on the mismatch. The regression corrupts a synthesized MP4 exactly that way and asserts rejection in under two seconds; before the fix it resolved with fabricated values.One open question I'm raising rather than fixing: a 12-bit extended JPEG currently reports
bitsAllocated: 12straight from the SOF precision byte, but DICOM allows only 8 or 16 for BitsAllocated — the conformant encoding is BitsAllocated 16 with BitsStored 12. The right place for that isbuildImageDataset(about five lines) when it lands in the next PR of this wave; I'd like a maintainer nod before encoding that policy.Seventeen tests in the package — the nine ported mp4Info ones plus the hand-written jpegInfo suite and the stts regression — all green, with no binary fixtures committed (everything is synthesized in memory).
🤖 Generated with Claude Code