Skip to content

[stb_vorbis] Fix setup_malloc, setup_temp_malloc, vendor, comment, and multiplicands bounding. - #1960

Open
AliceLR wants to merge 3 commits into
nothings:masterfrom
AliceLR:fix-setup-malloc
Open

AliceLR wants to merge 3 commits into
nothings:masterfrom
AliceLR:fix-setup-malloc

Conversation

@AliceLR

@AliceLR AliceLR commented Jun 3, 2026

Copy link
Copy Markdown

Marking as a draft for now since it's poorly tested, but this should fix #1933, #1947, and the second case in the comment #1168 (comment). However, it's not clear if this is the fix you actually want (particularly re: the definition of uint64 and various type-corrections).

@nothings I've noticed several dubious submissions duplicating parts of bug reports and patches I submitted years ago. Is there anything I can do to help?

Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc now reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.
@AliceLR
AliceLR force-pushed the fix-setup-malloc branch from f5b1507 to 66fc4c6 Compare June 5, 2026 00:13
@AliceLR

AliceLR commented Jun 5, 2026

Copy link
Copy Markdown
Author
  • I've replaced the simple typedef for uint64 with a more robust version copied from libxmp's common.h. This fragment is probably non-copyrightable.
  • I removed the creeping type corrections and reduced this patch down to what should be the bare minimum to fix the affected setup_malloc, setup_temp_malloc, and setup_temp_free calls.

@AliceLR
AliceLR marked this pull request as ready for review June 5, 2026 00:20
sezero pushed a commit to sezero/libxmp that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Mainstream P/R: nothings/stb#1960
Reference issue: libxmp#996
Also see: nothings/stb#1947
Also see: nothings/stb#1933
Also see: nothings/stb#1168 (comment)
sezero pushed a commit to sezero/libxmp that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Mainstream P/R: nothings/stb#1960
Reference issue: libxmp#996
Also see: nothings/stb#1947
Also see: nothings/stb#1933
Also see: nothings/stb#1168 (comment)
AliceLR added a commit to libxmp/libxmp that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Mainstream P/R: nothings/stb#1960
Reference issue: #996
Also see: nothings/stb#1947
Also see: nothings/stb#1933
Also see: nothings/stb#1168 (comment)

Co-authored-by: AliceLR <petrifiedrowan@gmail.com>
sezero pushed a commit to sezero/stb that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings#1947
Reference issue: nothings#1933
Also see       : nothings#1168 (comment)
Mainstream P/R : nothings#1960
sezero pushed a commit to icculus/SDL_sound that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960

(cherry picked from commit 19ae8a8)
sezero pushed a commit to icculus/SDL_sound that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960
sezero pushed a commit to libsdl-org/SDL_mixer that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960

(cherry picked from commit 369279b)
sezero pushed a commit to libsdl-org/SDL_mixer that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960
sezero pushed a commit to libsdl-org/SDL_mixer that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960

(cherry picked from commit 369279b)
sezero pushed a commit to libsdl-org/SDL_mixer that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960
sezero pushed a commit to libsdl-org/SDL_mixer that referenced this pull request Jun 5, 2026
Expands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960

(cherry picked from commit 52afb20)
Wohlstand added a commit to WohlSoft/SDL-Mixer-X that referenced this pull request Jun 5, 2026
Backported from libsdl-org/SDL_mixer@369279b

xpands the setup_malloc size parameter, and various calculations
that the Vorbis spec allows to exceed 32 bits, to uint64. setup_malloc
and setup_temp_malloc still reject allocations that exceed INT_MAX,
as the underlying memory fields are still 32 bit signed integers.

Reference issue: libxmp/libxmp#996
Reference issue: nothings/stb#1947
Reference issue: nothings/stb#1933
Also see       : nothings/stb#1168 (comment)
Mainstream P/R : nothings/stb#1960
@nothings

Copy link
Copy Markdown
Owner

Without putting too much thought into it, I think my preference would be that it's okay to use 64-bit to compute the products but to still bail if the size is larger than 32-bit, since it's surely a problematic file anyway, i.e. 64-bit locals okay, but not in structs.

@AliceLR

AliceLR commented Oct 25, 2026

Copy link
Copy Markdown
Author

Without putting too much thought into it, I think my preference would be that it's okay to use 64-bit to compute the products but to still bail if the size is larger than 32-bit, since it's surely a problematic file anyway, i.e. 64-bit locals okay, but not in structs.

That sounds reasonable. I will update this patch when I get a chance.

@nothings

Copy link
Copy Markdown
Owner

Also, the whole use of floor(pow) and floor(exp(log())) for integer powers, seems crazy to me, it should probably be done by repeated multiplication, or at least rounding with floor(...+0.5)? Weird that I did it that way in the first place.

@nothings

Copy link
Copy Markdown
Owner

Yeah, maybe better to just use #2021 .

@AliceLR

AliceLR commented Oct 25, 2026

Copy link
Copy Markdown
Author

Yeah, maybe better to just use #2021 .

That's also reasonable IMO; it is essentially what I would have implemented if you had rejected uint64 before that PR was opened.

@AliceLR

AliceLR commented Oct 25, 2026

Copy link
Copy Markdown
Author

I've pushed a second commit that limits uint64 to the bounding only. Aside from (I think) covering a few more integer overflow edge cases, it's not looking that different from #2021.

@AliceLR AliceLR changed the title [stb_vorbis] Increase setup_malloc size parameter to uint64. [stb_vorbis] Fix setup_malloc, setup_temp_malloc, vendor, comment, and multiplicands bounding. Oct 26, 2026
@AliceLR

AliceLR commented Oct 26, 2026

Copy link
Copy Markdown
Author

Removed uint64 altogether per #1933 (comment).

@rygorous

Copy link
Copy Markdown
Collaborator

At long last merged into dev branch, will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 stb_vorbis 5 merged-dev Merged into development branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stb_vorbis: integer overflow in codebook multiplicands allocation

3 participants