integer overflow in Tcl_AttemptSetObjLength() -> SEGFAULT
Closed / Fixed2553906fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2009-01-31 23:19:18
Hi *,
while testing with various incarnations of data appending to hammer the fix for #2494093, I stumbled over another one... This crash occurs in trunk, core-8-5-branch, as well as 8.4.19. The stack trace below is from HEAD (last updated today 2pm GMT). System is a Linux openSUSE 11.1 x86_64. Code to reproduce is as follows:
# ----
proc bar {} {
set f [string repeat "DEADBEEF" 1024] ;# for the crash in AppendUtfToUtfRep()
set r ""
set i 0
while {1} {
puts -nonewline stdout "$i\r"
set fl [string length $f]
if {($fl != [string length $r]) || 1} {
append r [string range $f 0 $fl]
}
incr i $fl
}
}
bar
# ----
The stack trace contains the first three levels with local vars, then only the calls...
(gdb) bt full
#0 0x00007ffff7b6102d in Tcl_AttemptSetObjLength (objPtr=0x637020, length=-2147467264)
at /home/matze/cvs/tcl_head/generic/tclStringObj.c:931
stringPtr = (String *) 0x64e0c0
#1 0x00007ffff7b61a37 in AppendUtfToUtfRep (objPtr=0x637020,
bytes=0x7ffe70000940 "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"..., numBytes=8192)
at /home/matze/cvs/tcl_head/generic/tclStringObj.c:1491
stringPtr = (String *) 0x64e0c0
newLength = 1073750016
oldLength = 1073741824
#2 0x00007ffff7b61625 in Tcl_AppendObjToObj (objPtr=0x637020, appendObjPtr=0x62c230)
at /home/matze/cvs/tcl_head/generic/tclStringObj.c:1269
stringPtr = (String *) 0x7ffe70002950
length = 8192
numChars = 1073750016
allOneByteChars = 1
bytes = 0x7ffe70000940 "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"...
#3 0x00007ffff7b75ccf in TclPtrSetVar (interp=0x606e10, varPtr=0x607e90, arrayPtr=0x0, part1Ptr=0x0, part2Ptr=0x0, newValuePtr=0x62c230,
flags=516, index=1) at /home/matze/cvs/tcl_head/generic/tclVar.c:1885
#4 0x00007ffff7afb455 in TclExecuteByteCode (interp=0x606e10, codePtr=0x649360) at /home/matze/cvs/tcl_head/generic/tclExecute.c:3365
#5 0x00007ffff7a8e5d0 in NRCallTEBC (data=0x62bfc8, interp=0x606e10, result=0) at /home/matze/cvs/tcl_head/generic/tclBasic.c:4328
#6 0x00007ffff7a8e28f in TclNRRunCallbacks (interp=0x606e10, result=0, rootPtr=0x0, tebcCall=0)
at /home/matze/cvs/tcl_head/generic/tclBasic.c:4243
#7 0x00007ffff7a8ddbc in Tcl_EvalObjv (interp=0x606e10, objc=1, objv=0x607ca0, flags=2097152)
at /home/matze/cvs/tcl_head/generic/tclBasic.c:4026
#8 0x00007ffff7a8fd7a in TclEvalEx (interp=0x606e10,
script=0x653810 "set i 1234567890\nset n /dev/zero\n\n# Tcl bug 2494093\nproc foo {n i} {\n set f [open $n r]\n fconfigure $f -translation binary -buffering full -buffersize 4096\n\n upvar #0 data($n,raw) r\n set r"..., numBytes=1157, flags=0, line=61)
at /home/matze/cvs/tcl_head/generic/tclBasic.c:5121
#9 0x00007ffff7a8f2b9 in Tcl_EvalEx (interp=0x606e10,
script=0x653810 "set i 1234567890\nset n /dev/zero\n\n# Tcl bug 2494093\nproc foo {n i} {\n set f [open $n r]\n fconfigure $f -translation binary -buffering full -buffersize 4096\n\n upvar #0 data($n,raw) r\n set r"..., numBytes=1157, flags=0)
at /home/matze/cvs/tcl_head/generic/tclBasic.c:4822
#10 0x00007ffff7b2ee71 in Tcl_FSEvalFileEx (interp=0x606e10, pathPtr=0x626c20, encodingName=0x0)
at /home/matze/cvs/tcl_head/generic/tclIOUtil.c:1753
#11 0x00007ffff7b37f62 in Tcl_Main (argc=-1, argv=0x7fffffffde68, appInitProc=0x400925 <Tcl_AppInit>)
at /home/matze/cvs/tcl_head/generic/tclMain.c:353
#12 0x000000000040091e in main (argc=2, argv=0x7fffffffde58) at /home/matze/cvs/tcl_head/unix/tclAppInit.c:87
If I see that correctly AppendUtfToUtfRep() is missing a check against INT_MAX at some place...
-- Matthias Kraft
matzek Ticket [2553906fff]: 1 change
[History diff]2009-02-01 06:20:12
dgp Ticket [2553906fff]: 1 change
[History diff]2009-02-01 08:13:32
dgpplain2009-02-02 12:50:11
Fix committed to HEAD. Please test. Backports on hold until a testing report confirms success, and so that they can happen along with those for 2494093.
matzekplain2009-02-02 23:41:09
Works for me on 8.4, 8.5, head and tested with AIX, HP-UX, Solaris, and Linux... -- Matthias Kraft
dgpplain2009-02-19 01:47:41
please give the HEAD another round of rigorous testing.
matzekplain2009-02-20 04:21:07
will do, but I am currently overloaded with paid work. It might be not before next week that I will find time ... kind regards -- Matthias Kraft
matzekplain2009-02-26 21:43:54
Used HEAD as of today, compiled and tested on various AIX, HP-UX, Linux, and Solaris machines. Looks good: It either aborts with "unable to realloc ... bytes" or with "max size for a Tcl value (2147483647 bytes) exceeded". One exception: Linux on a s390x mainframe. Here it seems the kernel is killing the process before Tcl gets a chance to abort. IIRC that's a feature of the Linux kernel. kind regards -- Matthias Kraft
ferrieuxplain2009-03-20 05:46:52
Re the s390 kill: if it is the oom_killer, please note that it is operates on a system-wide criterion (shortage of swap space, aka total vm exhausted). Does it realistically account for your case ? If yes, it would mean that you are actually very short on swap disk space (2G). Increasing it could help avoiding the "masking effect" and seeing the normal size threshold kick in.
matzekplain2009-03-20 21:31:14
It is the oom_killer, the machine I have available here only has 512 MB RAM and 1.5 GB swap. I cannot change that. The Mainframe is hosting quite a number of Linux VMs, changing parameters is a budget matter ... kind regards -- Matthias Kraft
ferrieuxplain2009-03-20 22:12:51
OK, so there's no mystery left it seems. This particular machine cannot reach the 2G size needed to exhibit the wanted behavior, but for those who can, it seems the problem is solved. Don, any reason not to close ?
dgpplain2009-03-20 22:25:42
again, I'm leaving open until I'm sure I've backported those fixes that make sense.
dgpplain2009-04-08 01:38:31
allow_comments - 1 backports complete
Log in (anonymous is fine) to add a comment.