[ https://issues.apache.org/jira/browse/XMLBEANS-474?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17777890#comment-17777890 ]
PJ Fanning commented on XMLBEANS-474: ------------------------------------- Saver is very old code and is very wasteful. Saving involves building up the data to output in memory and then saving it. The memory storage uses a byte[] or char[] (depending on usage) and they can only store Integer.MAX_VALUE entries. For byte[], that means approx 2Gb is the limit. There is no guarantee that the NegativeArraySizeException issue is the only issue as we approach this limit. It may be feasible to create a new variant of Saver that uses a temp file instead of an array but this is going to be pretty hard to get right. > NegativeArraySizeException thrown from TextSaver.resize > ------------------------------------------------------- > > Key: XMLBEANS-474 > URL: https://issues.apache.org/jira/browse/XMLBEANS-474 > Project: XMLBeans > Issue Type: Bug > Affects Versions: Version 2.5 > Reporter: Dan Faershtein > Priority: Major > Fix For: Version 5.2.0 > > Time Spent: 20m > Remaining Estimate: 0h > > TextSever.resize() > does not check if "newLen" is negative which can happen if requested size is > more than ( Integer.MAX_VALUE / 2) > consider core java implementation AbstractStringBuilder:expandCapacity: > void expandCapacity(int minimumCapacity) { > int newCapacity = (value.length + 1) * 2; > if (newCapacity < 0) { > newCapacity = Integer.MAX_VALUE; > } else if (minimumCapacity > newCapacity) { > newCapacity = minimumCapacity; > } > value = Arrays.copyOf(value, newCapacity); > } > Here is the exception stack trace: > Nov 18 16:09:31 localhost java.lang.NegativeArraySizeException > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver$TextSaver.resize(Saver.java:1695) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver$TextSaver.preEmit(Saver.java:1300) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver$TextSaver.emit(Saver.java:1231) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver$TextSaver.emitAttrHelper(Saver.java:1027) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver$TextSaver.emitElement(Saver.java:966) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver.processElement(Saver.java:476) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver.process(Saver.java:307) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Saver$TextSaver.saveToString(Saver.java:1859) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Cursor._xmlText(Cursor.java:546) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.store.Cursor.xmlText(Cursor.java:2436) > Nov 18 16:09:31 localhost at > org.apache.xmlbeans.impl.values.XmlObjectBase.xmlText(XmlObjectBase.java:1489) -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org