Issue522828

classification
Title: struct.pack('>NNs', v) fails for NN > 20
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: bckfnn Nosy List: bckfnn, nobody
Priority: normal Keywords:

Created on 2002-02-26.05:35:34 by anonymous, last changed 2002-03-11.13:40:15 by bckfnn.

Messages
msg593 (view) Author: Nobody/Anonymous (nobody) Date: 2002-02-26.05:35:34
When using struct.pack with Jython 2.1, an attempt to
pack a string longer than 20 characters will cause a
Java array overflow.  See below for example.

% jython
Jython 2.1 on java1.2 (JIT: sunwjit)
Type "copyright", "credits" or "license" for more
information.
>>> a = 'abcd'
>>> b = 8*a
>>> len(b)
32
>>> b
'abcdabcdabcdabcdabcdabcdabcdabcd'
>>> import struct
>>> struct.pack('>32s', b)
Traceback (innermost last):
  File "<console>", line 1, in ?
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at org.python.modules.struct$ByteStream.write(Compiled
Code)
	at
org.python.modules.struct$ByteStream.writeString(Compiled
Code)
	at
org.python.modules.struct$StringFormatDef.doPack(Compiled
Code)
	at org.python.modules.struct.pack(Compiled Code)
	at java.lang.reflect.Method.invoke(Native Method)
	at
org.python.core.PyReflectedFunction.__call__(Compiled
Code)
	at
org.python.core.PyReflectedFunction.__call__(Compiled
Code)
	at org.python.core.PyObject.__call__(Compiled Code)
	at org.python.core.PyObject.invoke(Compiled Code)
	at org.python.pycode._pyx9.f$0(Compiled Code)
	at org.python.pycode._pyx9.call_function(Compiled
Code)
	at org.python.core.PyTableCode.call(Compiled Code)
	at org.python.core.PyCode.call(Compiled Code)
	at org.python.core.Py.runCode(Compiled Code)
	at org.python.core.Py.exec(Compiled Code)
	at org.python.util.PythonInterpreter.exec(Compiled
Code)
	at
org.python.util.InteractiveInterpreter.runcode(Compiled
Code)
	at
org.python.util.InteractiveInterpreter.runsource(Compiled
Code)
	at
org.python.util.InteractiveInterpreter.runsource(Compiled
Code)
	at org.python.util.InteractiveConsole.push(Compiled
Code)
	at
org.python.util.InteractiveConsole.interact(Compiled
Code)
	at org.python.util.jython.main(Compiled Code)

java.lang.ArrayIndexOutOfBoundsException:
java.lang.ArrayIndexOutOfBoundsException
>>> 
msg594 (view) Author: Nobody/Anonymous (nobody) Date: 2002-02-27.02:05:47
Logged In: NO 

This doesn't happen if the string is much less than the
format size.  For example,

struct.pack('>32s', 'abc')

works fine.  It's only when the size is greater than 20 and
the string is also greater than 20 that things go haywire.

Bill
msg595 (view) Author: Finn Bock (bckfnn) Date: 2002-03-11.13:37:32
Logged In: YES 
user_id=4201

Added as test356
msg596 (view) Author: Finn Bock (bckfnn) Date: 2002-03-11.13:40:15
Logged In: YES 
user_id=4201

Fixed in struct.java: 2.6;
History
Date User Action Args
2002-02-26 05:35:34anonymouscreate