Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-12-02
16:32 • Closed ticket [851747ffff]: binary scan object sharing/reuse problem plus ... artifact: ed97ce92f1 user: dkf
09:31
Stop losing references when variables are repeated in [binary scan]. [851747] check-in: 4b0fb393bf user: dkf tags: core-8-4-branch
09:29
Stop losing references when variables are repeated in [binary scan]. [851747] check-in: e1aa93441d user: dkf tags: trunk
2003-12-01
23:37 • Ticket [851747ffff] binary scan object sharing/reuse problem status still ... artifact: eb18b3e957 user: dkf
23:29 • Ticket [851747ffff]: 1 change artifact: 6ddcae5ba9 user: dkf
21:41 • Ticket [851747ffff]: 4 changes artifact: fe53c62b22 user: dkf
21:35 • Ticket [851747ffff]: 4 changes artifact: 73978128cc user: dkf
21:28 • Ticket [851747ffff]: 4 changes artifact: 13698be413 user: dkf
21:28 • Ticket [851747ffff]: 1 change artifact: 81bfe976c1 user: dkf
20:27 • Ticket [851747ffff]: 1 change artifact: 3541fd64c6 user: dkf
20:15 • Ticket [851747ffff]: 4 changes artifact: 2a739bc9a8 user: dkf
20:13 • Ticket [851747ffff]: 4 changes artifact: ac95ff1cba user: cc_benny
18:57 • Ticket [851747ffff]: 7 changes artifact: ac1cba5cff user: vincentdarley
05:07 • Ticket [851747ffff]: 4 changes artifact: 206b1f07df user: obermeier
05:07 • Add attachment coredump.zip to ticket [851747ffff] artifact: f457e9d2f2 user: obermeier
2003-11-30
22:07 • New ticket [851747ffff] Coredump with Tcl 8.4.X (possibly binary scan). artifact: ade2d81547 user: obermeier

[binary scan] object sharing/reuse problem

Closed / Fixed851747ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-11-30 22:07:01
While working with the fileType function of TclLib, I 
encountered core dumps on both Linux and Windows 
with different versions of Tcl 8.4 (8.4.2, 8.4.4, 8.4.5).

The same code works with Tcl 8.3 on both platforms.

I succeeded to strip down the problem to the attached 
code.
This code applied to the four (identical) image files 
supplied in the attachment, dumps core.
You can avoid dumping core by
1. replacing the binary scan command as noted in the 
code or
2. by commenting out the line "set s [file size $filename]"

I noticed, that if I copy the files from the FAT32 
partition to a NTFS partition, it does not dump core, but 
still prints out different offset values, although the files 
are identical.

Core dumps also occur on Mac OS X with Tcl 8.4, but 
not with Tcl 8.3.
obermeierplain2003-12-01 05:07:01
File Added - 69128: coredump.zip
vincentdarleyplain2003-12-01 18:57:26
Logged In: YES 
user_id=32170

I can't reproduce this (I'm on Windows and only have NTFS),
although I do notice some strange behaviour regarding
finding the .ppm files at all...
cc_bennyplain2003-12-01 20:13:38
Logged In: YES 
user_id=143885

The code crashes with tclsh8.4 on my Linux/PPC box and also
on my Mac OS X box.  No problems with tclsh8.3 on either
platform.  The Mac OS X version says "abort: invalid block". 
IOW, some routine trashes the heap.  There seems to be a
a buffer overwrite in that [binary scan] variant.
dkfplain2003-12-01 20:15:02
Logged In: YES 
user_id=79902

I can reproduce this with 8.4.1 on WinXP/NTFS
dkf Ticket [851747ffff]: 1 change [History diff]2003-12-01 20:27:09
dkf Ticket [851747ffff]: 1 change [History diff]2003-12-01 21:28:43
dkfplain2003-12-01 21:28:44
Logged In: YES 
user_id=79902

The following script reproduces the fault for me:

set s
\xdf\xdf\xdb\xdf\xdf\xdb\xdf\xdf\xdb\xdf\xdf\xdb\xdf\xdf\xdb\xdf
binary scan $s IIII a b a a
binary scan $s IIII a b a a
binary scan $s IIII a b a a

In mem-debug mode (8.5a0 on UNIX), the fault happens in the
first [binary scan]!
dkfplain2003-12-01 21:35:18
Logged In: YES 
user_id=79902

Minimal script (in mem-debug mode):
   set s aaaabbbbaaaa
   binary scan $s III a a a
dkfplain2003-12-01 21:41:45
Logged In: YES 
user_id=79902

Commentary: This one is nasty.  It depends on the value
caching behaviour inside [binary scan] and requires that a
variable be written three times, once with value 1, then
with value 2, then with value 1 again, which the cache
(unsuccessfully) tries to share.

Fixing this requires either a much more expensive cache or
something to detect when the same variable is being written
more than twice (when a non-cached scheme has to be used.) Yuck.
dkf Ticket [851747ffff]: 1 change [History diff]2003-12-01 23:29:02
dkfplain2003-12-01 23:37:48
Logged In: YES 
user_id=79902

Also:
   binary scan /g/ ccc a a a
or any other triple.  The requirement is a write to a
particular variable at least three times with a write of a
value twice interspersed with another value.  The first
write puts an object in the cache, the second invalidates
that object, and the third write reuses the (now invalid)
object.
dkfplain2003-12-02 16:32:30
Logged In: YES 
user_id=79902

Fixed in HEAD and 8.4 branch
Log in (anonymous is fine) to add a comment.

Attachments: