Repository navigation
MP4: do not convert an out of range length to int - #1419
Merged
ufleisch merged 1 commit intoAug 16, 2026
Merged
Conversation
The mdhd duration is a signed 64 bit field in version 1 and the timescale sitting beside it is a 32 bit field that may be 1, so a 4 KB file can declare 2^62 units of a one-hertz clock. The millisecond length is then ~4.6e21 and the conversion to int is undefined: taglib/mp4/mp4properties.cpp:207:34: runtime error: 4.61169e+21 is outside the range of representable values of type 'int' The version 0 path reaches the same line with a 32 bit duration: taglib/mp4/mp4properties.cpp:207:34: runtime error: 4.29497e+12 is outside the range of representable values of type 'int' The mvhd fallback a few lines above feeds the same expression, so it is covered by the same guard. Leave the field at its default rather than converting. For the record, the other conversions in this file were checked and are not affected. The esds and alac nominal bitrates divide a 32 bit value by 1000.0, which cannot leave int's range, and the three calculateMdatLength() estimates are integer arithmetic on a long long rather than a double conversion. One report per file before the change, none after. The 18 MP4 files in tests/data report identical channels, sample rate, bitrate and length before and after, and the suite runs 576 tests either way. Assisted-By: Claude Code (Claude Opus 5)
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.
The last format in the class, after #1416, #1417 and #1418.
The
mdhdduration is a signed 64 bit field in version 1, and the timescale sitting beside it is a 32 bit field that may be 1. TagLib divides one by the other into adoubleand converts straight tointwith no range check, so a 4 KB file is enough:mp4properties.cpp:2074.61169e+21mdhdversion 1, timescale 1, duration 2^62mp4properties.cpp:2074.29497e+12mdhdversion 0, timescale 1, duration 2^32-1The
mvhdfallback a few lines above feeds the same expression, so the one guard covers it too.What I checked and left alone
This file has five other conversions that look like the same shape and are not:
:241and:255, the esds and alac nominal bitrates, divide a 32 bit value by1000.0. The largest possible result is about 4.3e6, comfortably insideint.:244,:262and:311estimate a bitrate fromcalculateMdatLength(), which returnslong long. That whole expression is integer arithmetic, so a narrowing there is implementation-defined rather than undefined, and not this bug.I mention it because "the other five look identical" is the obvious reviewer question, and I would rather answer it up front than have you check.
Regression evidence
tests/datareport identical channels, sample rate, bitrate and length before and after.master, not on a tree that also carried MPEG: do not convert out of range properties to int #1418 — and the two comparison binaries were hashed to confirm they differ.