History

wav: do not div by zero; validate sample rate and number of channels

Sigrid Solveig Haflínudóttir committed 4 years ago

Commit fe4a4fb1 parent 880732b1 file · +8 −3Browse files

Unified · Split

wav.c+8−3
@@ -18,7 +18,9 @@ int · 17 unmodified lines
1818 tagwav(Tagctx *ctx)
1919 {
2020 uchar *d;
21− int i, n, info, csz, sz;
21+ int i, n, info;
22+ u32int csz, x;
23+ uvlong sz;
2224
2325 d = (uchar*)ctx->buf;
2426
@@ -57,7 +59,10 @@ tagwav(Tagctx *ctx) · 32 unmodified lines
5759 csz -= 16;
5860 ctx->channels = le16u(d+2);
5961 ctx->samplerate = leuint(d+4);
60− ctx->duration = sz*1000 / leuint(d+8);
62+ x = leuint(d+8);
63+ if(ctx->channels < 1 || ctx->samplerate < 1 || x < 1)
64+ return -1;
65+ ctx->duration = sz*1000 / x;
6166 }else if(memcmp(d, "LIST", 4) == 0){
6267 sz = csz - 4;
6368 continue;
@@ -67,7 +72,7 @@ tagwav(Tagctx *ctx) · 3 unmodified lines
6772 csz++;
6873 for(n = 0; n < nelem(t); n++){
6974 if(memcmp(d, t[n].s, 4) == 0){
70− if(ctx->read(ctx, d, csz) != csz)
75+ if(ctx->read(ctx, d, csz) != (int)csz)
7176 return -1;
7277 d[csz-1] = 0;
7378 txtcb(ctx, t[n].type, "", d);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t