Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OOB Read when saving GIF of xsize=1 #5149

Merged
merged 2 commits into from Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Tests/test_file_gif.py
Expand Up @@ -74,10 +74,10 @@ def test_bilevel(optimize):
im.save(test_file, "GIF", optimize=optimize)
return len(test_file.getvalue())

assert test_grayscale(0) == 800
assert test_grayscale(1) == 44
assert test_bilevel(0) == 800
assert test_bilevel(1) == 800
assert test_grayscale(0) == 799
assert test_grayscale(1) == 43
assert test_bilevel(0) == 799
assert test_bilevel(1) == 799


def test_optimize_correctness():
Expand Down
9 changes: 7 additions & 2 deletions src/libImaging/GifEncode.c
Expand Up @@ -233,8 +233,13 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
}

}

this = state->buffer[state->x++];
/* Potential special case for xsize==1 */
if (state->x < state->xsize) {
this = state->buffer[state->x++];
} else {
EMIT_RUN(label0);
break;
}

if (this == context->last) {
context->count++;
Expand Down