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

shifting a negative signed value is undefined ("-1L << 16" in inflate.c) #183

Closed
cliffordwolf opened this issue Dec 31, 2016 · 2 comments
Closed

Comments

@cliffordwolf
Copy link

inflate.c triggers the following warning in clang version 3.8.0-2ubuntu4:

inflate.c:1507:61: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
    if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
                                                        ~~~ ^

I believe ~0UL << 16 has defined behavior and yields the expected result.

@madler
Copy link
Owner

madler commented Dec 31, 2016

This was fixed on the develop branch.

@madler madler closed this as completed Dec 31, 2016
@cliffordwolf
Copy link
Author

Oh, I have not seen that. My bad.
Thanks and a happy new year!

hzhuang1 pushed a commit to Linaro/warpdrive-zlib that referenced this issue Jul 31, 2019
Before this patch

cmake -DWITH_SANITIZERS=1
make
make test

used to fail with:

Running tests...
Test project /home/hansr/github/zlib/zlib-ng
    Start 1: example
1/2 Test madler#1: example ..........................***Failed    0.14 sec
    Start 2: example64
2/2 Test madler#2: example64 ........................***Failed    0.13 sec

==11605==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x62e000000595,0x62e0000053b5) and [0x62e000000400, 0x62e000005220) overlap
    #0 0x7fab3bcc9662 in __asan_memcpy (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x8c662)
    madler#1 0x40f936 in memcpy /usr/include/x86_64-linux-gnu/bits/string3.h:53
    madler#2 0x40f936 in read_buf /home/spop/s/zlib-ng/deflate.c:1122
    madler#3 0x410458 in deflate_stored /home/spop/s/zlib-ng/deflate.c:1394
    madler#4 0x4133d7 in zng_deflate /home/spop/s/zlib-ng/deflate.c:945
    madler#5 0x402253 in test_large_deflate /home/spop/s/zlib-ng/test/example.c:275
    madler#6 0x4014e8 in main /home/spop/s/zlib-ng/test/example.c:536
    madler#7 0x7fab3b89382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    madler#8 0x4018e8 in _start (/work/spop/zlib-ng/example+0x4018e8)

0x62e000000595 is located 405 bytes inside of 40000-byte region [0x62e000000400,0x62e00000a040)
allocated by thread T0 here:
    #0 0x7fab3bcd579a in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9879a)
    madler#1 0x40147a in main /home/spop/s/zlib-ng/test/example.c:516

0x62e000000400 is located 0 bytes inside of 40000-byte region [0x62e000000400,0x62e00000a040)
allocated by thread T0 here:
    #0 0x7fab3bcd579a in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9879a)
    madler#1 0x40147a in main /home/spop/s/zlib-ng/test/example.c:516

SUMMARY: AddressSanitizer: memcpy-param-overlap ??:0 __asan_memcpy
==11605==ABORTING

fix bug madler#183 following recommendations of Mika Lindqvist

 > the problem is in line c_stream.avail_in = (unsigned int)comprLen/2;
 > which feeds it too much data ... it should cap it to
 > c_stream.next_out - compr instead.
bucanero added a commit to bucanero/oosdk_libraries that referenced this issue Oct 31, 2021
shifting a negative signed value is undefined ("-1L << 16" in inflate.c)
madler/zlib#183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants