Issue2796

classification
Title: Request for oversize arrays not handled in BaseBytes and PyByteArray
Type: crash Severity: normal
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.2
process
Status: pending Resolution: fixed
Dependencies: Superseder:
Assigned To: jeff.allen Nosy List: jeff.allen
Priority: normal Keywords: test failure causes

Created on 2019-08-27.22:58:29 by jeff.allen, last changed 2019-09-08.12:25:08 by jeff.allen.

Messages
msg12642 (view) Author: Jeff Allen (jeff.allen) Date: 2019-08-27.22:58:28
I noticed this failure in test_bytes, running with 2.7.2a1 standalone JAR:

======================================================================
ERROR: test_repeat (__main__.ByteArrayTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Jeff\Documents\Jython\272b-trial\Lib\test\test_bytes.py", line 233, in test_repeat
    lambda: b * sys.maxsize)
  File "C:\Users\Jeff\Documents\Jython\272b-trial\kit\jython-standalone.jar\Lib\unittest\case.py", line 476, in assertRaises
    callableObj(*args, **kwargs)
  File "C:\Users\Jeff\Documents\Jython\272b-trial\Lib\test\test_bytes.py", line 233, in <lambda>
    lambda: b * sys.maxsize)
ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last destination index 2147483646 out of bounds for byte[2147483645]

----------------------------------------------------------------------

Note that the apparent array size 2147483645 is the result of b*sys.maxsize, where len(b) is 3, and a lossy long to int conversion, taking place in org.python.core.BaseBytes.repeatImpl(int). We should be comparing first with sys.maxsize.

In our tests this is usually masked by a MemoryError, but for some reason not in standalone.

Also look elsewhere in BaseBytes and PyByteArray for other places we allocate an array without checking the size.
msg12656 (view) Author: Jeff Allen (jeff.allen) Date: 2019-09-08.12:25:08
Fixed at https://hg.python.org/jython/rev/4bbc6d13f9af
History
Date User Action Args
2019-09-08 12:25:08jeff.allensetstatus: open -> pending
assignee: jeff.allen
resolution: fixed
messages: + msg12656
milestone: Jython 2.7.2
2019-08-27 22:58:29jeff.allencreate