| Ticket UUID: | 5c51be6411e40f5181c94554a19a3f4d6499dc50 | |||
| Title: | Buffer over-read in Tk_PhotoPutBlock() and Tk_PhotoPutZoomedBlock() | |||
| Type: | Patch | Version: | core-8-6-branch | |
| Submitter: | chrstphrchvz | Created on: | 2020-05-14 19:34:34 | |
| Subsystem: | 41. Photo Images | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2020-06-27 09:32:49 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2020-06-27 09:32:49 | |||
| Description: |
Was introduced by [11192077fd]. Discovered by occasional crash (segmentation fault) when running test suite on Tk Aqua, however this issue affects all platforms (I have verified Valgrind memcheck at least reports "Invalid read" for it on Linux). For
photo1 copy photo1 -from 2 1 -to 4 5 300 300
For
photo1 copy photo1 -from 1 0 -to 4 5 300 300 -zoom 1 2
These examples trigger the issue because in block.pixelPtr += options.fromX * block.pixelSize + options.fromY * block.pitch; block.width = options.fromX2 - options.fromX; block.height = options.fromY2 - options.fromY; This adjusts
memcpy(sourceBlock.pixelPtr, blockPtr->pixelPtr, sourceBlock.height * sourceBlock.pitch); But Similarly, for imgPhoto-12.3, 4 bytes are read past the end of Q: For any given Assuming the latter, the attached patch I believe fixes the issue in both | |||
| User Comments: |
fvogel added on 2020-06-27 09:32:49:
Merged in core-8-6-branch and trunk. fvogel added on 2020-06-06 08:57:24: Right, --trace-children=yes was the missing bit.
So now I'm reproducing what you see. Interesting to observe that:
- Saying CFLAGS="-DPURIFY" is needed to see the invalid read for imgPhoto-10.3 but it's not needed for imgPhoto-12.3
- There is no difference in what is observed with gcc or clang compilers (for the records)
I can now confirm that with the patch valgrind does no longer report invalid reads for these two tests.
The last thing that still puzzles me slightly is that for imgPhoto-12.3 valgrind reports an invalid read of size 2 whereas your computation (that I have checked on my side and found correct) would lead to reporting an invalid read of size 4 instead.
chrstphrchvz added on 2020-06-04 02:25:18:
If using fvogel added on 2020-06-03 20:11:39: Hmmm. Still no success on my side. chrstphrchvz added on 2020-06-02 05:56:04:
I forgot to mention that I compiled Tcl and Tk with fvogel added on 2020-06-01 13:58:57: @Christopher: I tried to reproduce your valgrind results, so I tried: valgrind make test TESTFLAGS="-file imgPhoto.test -verbose beps -match imgPhoto-1[02].3"This didn't produce any "Invalid read" output with core-8-6-branch. Could you teach me your recipe? jan.nijtmans added on 2020-05-19 16:46:55: Thanks, @françois, for taking this! chrstphrchvz added on 2020-05-17 01:39:27: I forgot to change the placeholder bug id before posting the patch; thanks for fixing that Francois. fvogel added on 2020-05-16 13:00:45: Thanks for this detailed analysis and patch. I understand the issue and I think I agree with the fix. I have committed it in branch bug-5c51be6411. | |||
Attachments:
- 5c51be6411-cpyLen.diff [download] added by chrstphrchvz on 2020-05-14 19:48:29. [details]
