Skip to content

Commit

Permalink
Add test for aufile_set_position
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
larsimmisch committed Nov 20, 2023
1 parent 8c626be commit 1f86e2b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rem/aufile/aufile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = max((off_t)datasize, pos);

if (fseek(af->f, pos, SEEK_CUR) < 0)
return errno;

af->nread = pos;

return 0;
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set(SRCS
aubuf.c
aulength.c
aulevel.c
aupos.c
auresamp.c
av1.c
base64.c
Expand Down
Binary file modified test/data/beep.wav
Binary file not shown.
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static const struct test tests[] = {
TEST(test_aubuf),
TEST(test_aulength),
TEST(test_aulevel),
TEST(test_auposition),
TEST(test_auresamp),
TEST(test_async),
TEST(test_av1),
Expand Down
1 change: 1 addition & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ int test_aes_gcm(void);
int test_aubuf(void);
int test_aulevel(void);
int test_aulength(void);
int test_auposition(void);
int test_auresamp(void);
int test_async(void);
int test_av1(void);
Expand Down

0 comments on commit 1f86e2b

Please sign in to comment.