Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathis Rosenhauer
libaec
Commits
fe0fbef9
Commit
fe0fbef9
authored
Sep 04, 2018
by
Mathis Rosenhauer
Browse files
Fix #10 ubsan issue in decoding
parent
4efbc51a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/decode.c
View file @
fe0fbef9
...
...
@@ -68,7 +68,7 @@
static void flush_##KIND(struct aec_stream *strm) \
{ \
uint32_t *flush_end, *bp, half_d; \
int32_t
data, m;
\
u
int32_t
xmax, d, data, m;
\
struct internal_state *state = strm->state; \
\
flush_end = state->rsip; \
...
...
@@ -87,11 +87,11 @@
} \
\
data = state->last_out; \
xmax = state->xmax; \
\
if (state->xmin == 0) { \
uint32_t
xmax, med, d;
\
uint32_t
med;
\
med = state->xmax / 2 + 1; \
xmax = state->xmax; \
\
for (bp = state->flush_start; bp < flush_end; bp++) { \
uint32_t mask; \
...
...
@@ -101,36 +101,33 @@
mask = (data & med)?xmax:0; \
\
/*in this case: xmax - data == xmax ^ data */
\
if (half_d <= (mask ^
(uint32_t)data)) {
\
if (half_d <= (mask ^
data)) {
\
data += (d >> 1)^(~((d & 1) - 1)); \
} else { \
data = mask ^ d; \
} \
put_##KIND(strm,
(uint32_t)data);
\
put_##KIND(strm,
data);
\
} \
state->last_out = data; \
} else { \
int32_t xmax, d; \
xmax = state->xmax; \
\
for (bp = state->flush_start; bp < flush_end; bp++) { \
d = *bp; \
half_d = (
(uint32_t)
d >> 1) + (d & 1); \
half_d = (d >> 1) + (d & 1);
\
\
if (data < 0) {
\
if (half_d <= xmax +
(uint32_t)
data + 1) { \
data += (
(uint32_t)
d >> 1)^(~((d & 1) - 1)); \
if (
(int32_t)
data < 0) { \
if (half_d <= xmax + data + 1) {
\
data += (d >> 1)^(~((d & 1) - 1));
\
} else { \
data = d - xmax - 1; \
} \
} else { \
if (half_d <= xmax -
(uint32_t)data) {
\
data += (
(uint32_t)
d >> 1)^(~((d & 1) - 1)); \
if (half_d <= xmax -
data) {
\
data += (d >> 1)^(~((d & 1) - 1));
\
} else { \
data = xmax - d; \
} \
} \
put_##KIND(strm,
(uint32_t)data);
\
put_##KIND(strm,
data);
\
} \
state->last_out = data; \
} \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment