Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer overflow during unfolding of the rice residual #61

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

MarkKremer
Copy link
Collaborator

@ktmf01
Copy link

ktmf01 commented Oct 24, 2023

This is additionally documented here: https://www.ietf.org/archive/id/draft-ietf-cellar-flac-12.html#name-rice-coding

When folding (i.e., zig-zag encoding) the residual sample values, no extra bits are needed when the absolute value of each residual sample is first stored in an unsigned data type of the size of the last step, then doubled, and then has one subtracted depending on whether the residual sample was positive or negative. Many implementations, however, choose to require one extra bit of data type size so zig-zag encoding can happen in one step and without a cast instead of the procedure described in the previous sentence.

edit: uhh, I just realize this is for encoding. For decoding it is a little different.

@mewmew
Copy link
Member

mewmew commented Oct 24, 2023

Wonderful! Thanks @MarkKremer for the fix and @ktmf01 for the docs : )

This is truly open source at its finest!

Cheers,
Robin

@mewmew
Copy link
Member

mewmew commented Oct 24, 2023

The v1.0.9 release has now been tagged.

Very happy to see that the audio samples of the IETF test cases are now correctly decoded by mewkiz/flac.

Cheerful regards,
Henry & Robin

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.

3 participants