Skip to content

psd: Fix segfault on architectures where char is unsigned (like ARM)

Adrian Bunk requested to merge (removed):master into master

https://buildd.debian.org/status/fetch.php?pkg=kimageformats&arch=arm64&ver=5.94.0-1&stamp=1653495641&raw=0

94% tests passed, 1 tests failed out of 17

Total Test time (real) =   0.41 sec

The following tests FAILED:
	  3 - kimageformats-read-psd (SEGFAULT)
Errors while running CTest
make[2]: *** [Makefile:74: test] Error 8
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000ffffa7014534 in ?? () from /lib/aarch64-linux-gnu/libc.so.6
(gdb) bt
#0  0x0000ffffa7014534 in ?? () from /lib/aarch64-linux-gnu/libc.so.6
#1  0x0000ffffa23c10c4 in memset (__len=<optimized out>, __ch=<optimized out>, 
    __dest=0xaaaaf5416428)
    at /usr/include/aarch64-linux-gnu/bits/string_fortified.h:59
#2  (anonymous namespace)::decompress (olen=970, 
    output=0xaaaaf5416428 '\377' <repeats 200 times>..., ilen=46, 
    input=0xaaaaf5425438 '\377' <repeats 200 times>...)
    at ./src/imageformats/psd.cpp:515
#3  (anonymous namespace)::LoadPSD (img=..., header=..., stream=...)
    at ./src/imageformats/psd.cpp:724
#4  PSDHandler::read (this=<optimized out>, image=0xffffd4b75dc8)
    at ./src/imageformats/psd.cpp:814
#5  0x0000ffffa78272d8 in QImageReader::read(QImage*) ()
   from /usr/lib/aarch64-linux-gnu/libQt5Gui.so.5
#6  0x0000aaaadb4040cc in main (argc=<optimized out>, argv=<optimized out>)
    at ./autotests/readtest.cpp:137
(gdb) frame 2
#2  (anonymous namespace)::decompress (olen=970, 
    output=0xaaaaf5416428 '\377' <repeats 200 times>..., ilen=46, 
    input=0xaaaaf5425438 '\377' <repeats 200 times>...)
    at ./src/imageformats/psd.cpp:515
515                 memset(output + j, input[ip++], size_t(rr));
(gdb) print rr
$1 = -254
(gdb)

Cast once when reading from input[] instead of at every user (which missed the user setting rr).

@mircomir This fixes commit 98f19c60

@pino FYI

Merge request reports