Skip to content

mp3decoder inbuf update fix - #11219

Merged
tannewt merged 3 commits into
adafruit:mainfrom
FoamyGuy:audiomp3_fix
Aug 21, 2026
Merged

mp3decoder inbuf update fix#11219
tannewt merged 3 commits into
adafruit:mainfrom
FoamyGuy:audiomp3_fix

Conversation

@FoamyGuy

Copy link
Copy Markdown
Collaborator

This fixes an issue that can arise when the MP3Decoder is reading from a source that runs background tasks during the read. No such source exists today but #11217 adds one. The EMMC driver implemented in that PR runs background tasks, so decoding an MP3 from it caused it to call mp3file_update_inbuf_cb() again while in the middle of the previous read.

INPUT_BUFFER_SPACE() is signed but to_read is not, so a negative space would wrap and be passed to stream_read()

Fixed by preventing background tasks while mp3 decoder fills inbuff and clamping logic for to_read.

I confirmed that this fixes the issue with decoding mp3s from the sp1emmc module in #11217. I think this fix stands aside from the SP-1 support because it would bite any other source that runs runs background tasks while getting the file data.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One, style comment. Good otherwise.

Comment thread shared-module/audiomp3/MP3Decoder.c Outdated
return result;
}

static bool mp3file_update_inbuf_always_impl(audiomp3_mp3file_obj_t *self, bool block_ok) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't do it this way because it adds another function to think about. Instead, just put prevent and allow in the existing function.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in the latest commit to remove the extra function layer.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs further changes to work. New commit coming in a bit.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with the latest commit. This needed to have allow()s added to the other exit paths.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. Thanks! This actually fixes the exception case. It wouldn't be run with the wrapper because of the weird unwinding that exceptions do.

@tannewt
tannewt merged commit 3113c1d into adafruit:main Aug 21, 2026
550 checks passed
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