libtags: flac: check sample rate before dividing by zero; also check number of channels

This commit is contained in:
Sigrid Solveig Haflínudóttir 2022-03-30 16:59:35 +00:00
parent bc5b0254d0
commit 12802b94c6

View file

@ -1,7 +1,7 @@
/* https://xiph.org/flac/format.html */ /* https://xiph.org/flac/format.html */
#include "tagspriv.h" #include "tagspriv.h"
#define beu3(d) ((d)[0]<<16 | (d)[1]<<8 | (d)[2]<<0) #define beu3(d) ((d)[0]<<16 | (d)[1]<<8 | (d)[2]<<0)
int int
tagflac(Tagctx *ctx) tagflac(Tagctx *ctx)
@ -18,6 +18,9 @@ tagflac(Tagctx *ctx)
sz = beu3(&d[5]); /* size of the stream info */ sz = beu3(&d[5]); /* size of the stream info */
ctx->samplerate = beu3(&d[18]) >> 4; ctx->samplerate = beu3(&d[18]) >> 4;
ctx->channels = ((d[20]>>1) & 7) + 1; ctx->channels = ((d[20]>>1) & 7) + 1;
if(ctx->samplerate < 1 || ctx->channels < 1)
return -1;
g = (uvlong)(d[21] & 0xf)<<32 | beu3(&d[22])<<8 | d[25]; g = (uvlong)(d[21] & 0xf)<<32 | beu3(&d[22])<<8 | d[25];
ctx->duration = g * 1000 / ctx->samplerate; ctx->duration = g * 1000 / ctx->samplerate;