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

Security Issue: Buffer / Heap Overflow #3

Closed
nafiez opened this issue May 3, 2018 · 0 comments
Closed

Security Issue: Buffer / Heap Overflow #3

nafiez opened this issue May 3, 2018 · 0 comments
Assignees
Labels

Comments

@nafiez
Copy link

nafiez commented May 3, 2018

cc @RamadhanAmizudin

There's an buffer overflow found in ngiflib.c in line 206. Size of tocopy exceeded the pixels size and when copying into context->frbuff_p.p8 it overflow here. Proof of ASAN output:

john@clufuzz:~/ngiflib/ngif$ ./SDLaffgif out/crashes/id:000007,sig:06,src:000000,op:flip1,pos:586
GIF89a
320x200 7bits 128 couleurs bg=0
BLOCK SIGNATURE 0x21 !
extension (id=0xfe)
-------------------- Comment extension --------------------
:::::::::::::::::::::::::::::::::::::::::::::::::::
: Multi-image GIF89a created with CompuMake Tools :
:::::::::::::::::::::::::::::::::::::::::::::::::::

=================================================================
==3568==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x63000000fe00 at pc 0x7fc5dfe17904 bp 0x7ffd40601780 sp 0x7ffd40600f28
WRITE of size 1 at 0x63000000fe00 thread T0
#0 0x7fc5dfe17903 in __asan_memcpy (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x8c903)
#1 0x40bb4b in memcpy /usr/include/x86_64-linux-gnu/bits/string3.h:53
#2 0x40bb4b in WritePixels /home/john/ngiflib/ngif/ngiflib.c:206
#3 0x40bb4b in DecodeGifImg /home/john/ngiflib/ngif/ngiflib.c:548
#4 0x411cc3 in LoadGif /home/john/ngiflib/ngif/ngiflib.c:784
#5 0x404d5f in SDL_LoadAnimatedGif /home/john/ngiflib/ngif/ngiflibSDL.c:136
#6 0x401fa7 in main /home/john/ngiflib/ngif/SDLaffgif.c:107
#7 0x7fc5df74882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x403118 in _start (/home/john/ngiflib/ngif/SDLaffgif+0x403118)

0x63000000fe00 is located 0 bytes to the right of 64000-byte region [0x630000000400,0x63000000fe00)
allocated by thread T0 here:
#0 0x7fc5dfe23602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
#1 0x41390b in LoadGif /home/john/ngiflib/ngif/ngiflib.c:607

SUMMARY: AddressSanitizer: heap-buffer-overflow ??:0 __asan_memcpy
Shadow bytes around the buggy address:
0x0c607fff9f70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fff9f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fff9f90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fff9fa0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fff9fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c607fff9fc0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c607fff9fd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c607fff9fe0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c607fff9ff0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c607fffa000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c607fffa010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap right redzone: fb
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
==3568==ABORTING

Affected code:
static void WritePixels(struct ngiflib_img * i, struct ngiflib_decode_context * context, const u8 * pixels, u16 n) {
u16 tocopy;
struct ngiflib_gif * p = i->parent;

while(n > 0) {
	tocopy = (context->Xtogo < n) ? context->Xtogo : n;
	if(!i->gce.transparent_flag) {

#ifndef NGIFLIB_INDEXED_ONLY
if(p->mode & NGIFLIB_MODE_INDEXED) {
#endif /* NGIFLIB_INDEXED_ONLY */
ngiflib_memcpy(context->frbuff_p.p8, pixels, tocopy); // crash happened here
pixels += tocopy;

Test case here:
corpus_1.zip

@miniupnp miniupnp self-assigned this May 3, 2018
@miniupnp miniupnp added the bug label May 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants