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

rem/aufile: test and fix aufile_set_position nread #1010

Merged
merged 5 commits into from
Nov 23, 2023

Conversation

larsimmisch
Copy link
Contributor

Also fix a bug: wav files can contain data after the data chunk. If we don't update nread in aufile_set_position, we can read invalid data.

(Write a test, find a bug)

Also fix a bug: wav files can contain data after the data chunk. If we don't update nread in aufile_set_position, we can read invalid data.
@cspiel1
Copy link
Collaborator

cspiel1 commented Nov 21, 2023

Tomorrow is release day and this is a bugfix with a unit test.
Is the bug critical? Does it happen for many/usual WAV files?

test/aupos.c Outdated

int err = aufile_open(&af, &prm, path, AUFILE_READ);
if (err)
TEST_ERR(err);
Copy link
Collaborator

Choose a reason for hiding this comment

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

TEST_ERR already includes the check if (err)

@@ -307,8 +307,12 @@ int aufile_set_position(struct aufile *af, const struct aufile_prm *prm,
off_t pos = (off_t)(prm->srate * aufmt_sample_size(prm->fmt)
* prm->channels * pos_ms / 1000);

pos = min((off_t)datasize, pos);
Copy link
Collaborator

@cspiel1 cspiel1 Nov 21, 2023

Choose a reason for hiding this comment

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

SEEK_CUR sets the position relative to the current position.

What is datasize after wav_header_decode() returns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The size of the data chunk, i.e. the size of the PCM data in bytes.

Copy link
Contributor Author

@larsimmisch larsimmisch Nov 21, 2023

Choose a reason for hiding this comment

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

The datasize was 1082 instead of 1072 - the file was 67.625 ms long. I've cut it to 67ms exactly now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand why the windows tests are failing, I'll try to reproduce

Copy link
Collaborator

Choose a reason for hiding this comment

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

The datasize was 1082 instead of 1072 - the file was 67.625 ms long. I've cut it to 67ms exactly now

So, now you fixed the WAV file? Shouldn't we test that it doesn't read too far?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that seemed simpler than fixing the test (i.e. allowing that less than 1ms can be read).

I can extend the test to make sure we don't read too far, that would make sense too.

@larsimmisch
Copy link
Contributor Author

Tomorrow is release day and this is a bugfix with a unit test.
Is the bug critical? Does it happen for many/usual WAV files?

aufile_set_position is fairly new, I don't think this is critical.

@cspiel1 cspiel1 added this to the v3.8.0 milestone Nov 21, 2023
@sreimers sreimers changed the title Add test for aufile_set_position rem/aufile: test and fix aufile_set_position Nov 23, 2023
@sreimers sreimers changed the title rem/aufile: test and fix aufile_set_position rem/aufile: test and fix aufile_set_position nread Nov 23, 2023
@sreimers sreimers merged commit 544b1db into baresip:main Nov 23, 2023
35 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.

3 participants