History

avcodec/scpr: check if total_freq is 0 in decode0

Fixes SIGFPE, closes #6196.

Paul B Mahol committed 9 years ago

Commit 86ab6b61 parent 33de0fe1 file · +19 −6Browse files

Unified · Split

libavcodec/scpr.c+19−6
@@ -63,7 +63,7 @@ typedef struct SCPRContext { · 62 unmodified lines
6363 int cxshift;
6464
6565 int (*get_freq)(RangeCoder *rc, unsigned total_freq, unsigned *freq);
66− void (*decode)(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsigned freq, unsigned total_freq);
66+ int (*decode)(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsigned freq, unsigned total_freq);
6767 } SCPRContext;
6868
6969 static void init_rangecoder(RangeCoder *rc, GetByteContext *gb)
@@ -130,7 +130,7 @@ static void reinit_tables(SCPRContext *s) · 60 unmodified lines
130130 s->mv_model[1][512] = 512;
131131 }
132132
133−static void decode(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsigned freq, unsigned total_freq)
133+static int decode(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsigned freq, unsigned total_freq)
134134 {
135135 rc->code -= cumFreq * rc->range;
136136 rc->range *= freq;
@@ -140,6 +140,8 @@ static void decode(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsigne · 3 unmodified lines
140140 rc->code = (rc->code << 8) | byte;
141141 rc->range <<= 8;
142142 }
143+
144+ return 0;
143145 }
144146
145147 static int get_freq(RangeCoder *rc, unsigned total_freq, unsigned *freq)
@@ -157,9 +159,14 @@ static int get_freq(RangeCoder *rc, unsigned total_freq, unsigned *freq) · 11 unmodified lines
157159 return 0;
158160 }
159161
160−static void decode0(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsigned freq, unsigned total_freq)
162+static int decode0(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsigned freq, unsigned total_freq)
161163 {
162− int t = rc->range * (uint64_t)cumFreq / total_freq;
164+ int t;
165+
166+ if (total_freq == 0)
167+ return AVERROR_INVALIDDATA;
168+
169+ t = rc->range * (uint64_t)cumFreq / total_freq;
163170
164171 rc->code1 += t + 1;
165172 rc->range = rc->range * (uint64_t)(freq + cumFreq) / total_freq - (t + 1);
@@ -170,6 +177,8 @@ static void decode0(GetByteContext *gb, RangeCoder *rc, unsigned cumFreq, unsign · 4 unmodified lines
170177 rc->code1 <<= 8;
171178 rc->range <<= 8;
172179 }
180+
181+ return 0;
173182 }
174183
175184 static int get_freq0(RangeCoder *rc, unsigned total_freq, unsigned *freq)
@@ -202,7 +211,8 @@ static int decode_value(SCPRContext *s, unsigned *cnt, unsigned maxc, unsigned s · 26 unmodified lines
202211 break;
203212 c++;
204213 }
205− s->decode(gb, rc, cumfr, cnt_c, totfr);
214+ if ((ret = s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
215+ return ret;
206216
207217 cnt[c] = cnt_c + step;
208218 totfr += step;
@@ -251,7 +261,10 @@ static int decode_unit(SCPRContext *s, PixelModel *pixel, unsigned step, unsigne · 42 unmodified lines
251261 break;
252262 c++;
253263 }
254− s->decode(gb, rc, cumfr, cnt_c, totfr);
264+
265+ if ((ret = s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
266+ return ret;
267+
255268 pixel->freq[c] = cnt_c + step;
256269 pixel->lookup[x] = cnt_x + step;
257270 totfr += step;

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