Fedora package: libjpeg-turbo-1.2.1-1.fc17.x86_64
When decoding certain images with a non-unity scale_denom, valgrind complains about uninitialized bytes in the output buffer.
$ valgrind --quiet --track-origins=yes djpeg -scale 1/2 -outfile out.pnm sample.jpg
==31216== Syscall param write(buf) points to uninitialised byte(s)
==31216== at 0x3D1C8E4940: __write_nocancel (syscall-template.S:82)
==31216== by 0x3D1C875FC2: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1289)
==31216== by 0x3D1C875EA1: new_do_write (fileops.c:543)
==31216== by 0x3D1C876D44: _IO_do_write@@GLIBC_2.2.5 (fileops.c:516)
==31216== by 0x3D1C876A2F: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1371)
==31216== by 0x3D1C86C62C: fwrite (iofwrite.c:45)
==31216== by 0x401133: main (djpeg.c:595)
==31216== Address 0x4c1000f is not stack'd, malloc'd or (recently) free'd
==31216== Uninitialised value was created by a heap allocation
==31216== at 0x4A0884D: malloc (vg_replace_malloc.c:263)
==31216== by 0x3D284285E8: alloc_large (jmemmgr.c:376)
==31216== by 0x3D28428870: alloc_sarray (jmemmgr.c:453)
==31216== by 0x3D2841BCE7: jinit_d_main_controller (jdmainct.c:510)
==31216== by 0x3D2841EE15: jinit_master_decompress (jdmaster.c:437)
==31216== by 0x3D284160C4: jpeg_start_decompress (jdapistd.c:44)
==31216== by 0x4010EE: main (djpeg.c:586)
==31216==
Sample image
I've seen this before, but I think it occurs with the regular libjpeg code as well. Can you confirm? I don't think it's a real bug but rather is due to valgrind not properly detecting when the bytes get initialized.
Neither libjpeg 6b nor 8d produce the warning, at least with this particular image. OTOH, libjpeg-turbo 1.2.1 compiled from source does produce the warning, so the problem isn't in the Fedora packaging.
Can't reproduce using the sample image you attached. Again, I've seen this issue before, so I believe it's happening. It just seems to be inconsistent.
I don't have a lot of time to devote to this, so if you can provide any additional information or assistance with reproducing the problem, that would be great.
I was also able to reproduce this with the sample image and libjpeg-turbo 1.2.1 compiled on 32-bit Ubuntu 12.04.
How can I help? I'm willing to find a reproducer that works on your Linux distro, test alternative binaries, etc.
If you can figure out how to repro it on Centos or Red Hat Enterprise 5, that would greatly accelerate the process of getting a fix. I feel like it is probably a minor issue, but without a consistent way to reproduce it, it would require many hours of diagnosis, and I don't have those hours available right now.
I have been unable to reproduce the problem on 32-bit CentOS 5.8.
On Fedora 17, I can consistently reproduce with Valgrind 3.7.0-4.fc17, and consistently cannot reproduce with Valgrind 3.8.1-4.fc17 and the same binary. Ubuntu 12.04 also ships Valgrind 3.7.0; CentOS 5 ships 3.5.0. I think this is a Valgrind issue, not a libjpeg-turbo bug.
OK, closing for now. If the situation changes, we can re-open it.
I found another reproducer:
This is on 64-bit RHEL 5.11, with libjpeg-turbo 1.3.90 and Valgrind 3.10.0 installed from source. I can also reproduce this on 32-bit RHEL 5.11, and with libjpeg-turbo 1.3.1. Valgrind 3.5.0, as shipped with RHEL 5, does not produce the warning.
Apparently SourceForge mangled the sample from my previous message. Here it is in a tarball.
I can still reproduce with 64-bit RHEL 5.11, Valgrind 3.10.1, and libjpeg-turbo 1.4.0. The problem goes away when built
--without-simd.Please reopen the bug if you think this is worth pursuing. Otherwise I'll desist and update my valgrind suppressions. :-)
I was able to repro it using the later version of valgrind, and I narrowed it down to something in simd/jdcolext-sse2[-64].asm. As to what that something is, I don't know, and I unfortunately don't have time to look into it in detail right now.
Note that valgrind 3.7.0 is the earliest version that reproduces this.