[openal] Fix AL_SAMPLE_OFFSET and AL_BYTE_OFFSET with buffer 0 - #27420
Open
sbc100 wants to merge 1 commit into
Open
[openal] Fix AL_SAMPLE_OFFSET and AL_BYTE_OFFSET with buffer 0#27420sbc100 wants to merge 1 commit into
sbc100 wants to merge 1 commit into
Conversation
When `AL_SAMPLE_OFFSET` or `AL_BYTE_OFFSET` is set on a source, the
library looks up the format of the queued audio data to convert the
offset into seconds for `sourceSeek`.
Previously, this iteration used `for (var bufId in src.bufQueue)` and
checked `if (bufId)`. Because `for..in` iterates over array index
strings (`"0"`, `"1"`, etc.), `bufId` received `"0"` on the first
iteration. In JavaScript, non-empty strings are truthy, so `if (bufId)`
evaluated `if ("0")`, which is always true.
As a result, the loop never skipped index 0. If `src.bufQueue[0]`
happened to be the default placeholder dummy zero buffer (which has
`frequency: 0`), it would read `frequency = 0` and cause a division by
zero (`value /= 0`), failing range validation with `AL_INVALID_VALUE`.
This change replaces both loops in `src/lib/libopenal.js` with
`for (var buf of src.bufQueue)` and checks `if (buf.id !== 0)`. A new
test case is added to `test/openal/test_openal_error.c` to verify this
behavior.
Collaborator
Author
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.
When
AL_SAMPLE_OFFSETorAL_BYTE_OFFSETis set on a source, the library looks up the format of the queued audio data to convert the offset into seconds forsourceSeek.Previously, this iteration used
for (var bufId in src.bufQueue)and checkedif (bufId). Becausefor..initerates over array index strings ("0","1", etc.),bufIdreceived"0"on the first iteration. In JavaScript, non-empty strings are truthy, soif (bufId)evaluatedif ("0"), which is always true.As a result, the loop never skipped index 0. If
src.bufQueue[0]happened to be the default placeholder dummy zero buffer (which hasfrequency: 0), it would readfrequency = 0and cause a division by zero (value /= 0), failing range validation withAL_INVALID_VALUE.This change replaces both loops in
src/lib/libopenal.jswithfor (var buf of src.bufQueue)and checksif (buf.id !== 0). A new test case is added totest/openal/test_openal_error.cto verify this behavior.The original bug was introduced in fcf8d12.
It seems that there was an attempt to fix this in #10466 but I think this code always yield true both before and after this change because "0" string is truthy.