You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2012/04/25 15:45:56 UTC

DO NOT REPLY [Bug 53147] New: Reordering and removing sheet causes internal data inconsistency

https://issues.apache.org/bugzilla/show_bug.cgi?id=53147

             Bug #: 53147
           Summary: Reordering and removing sheet causes internal data
                    inconsistency
           Product: POI
           Version: unspecified
          Platform: PC
        OS/Version: Windows Vista
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: recyclebin5385@yahoo.co.jp
    Classification: Unclassified


Created attachment 28683
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28683
test code and patch

I changed the order of sheets in a workbook by invoking method
setSheetOrder(String, int) of class org.apache.poi.hssf.usermodel.HSSFWorkbook
and removed one sheet by invoking method removeSheetAt(int).
Then I tried to save the workbook by invoking method write(OutputStream).
But a strange Exception was thrown and I could not save the workbook.
Below is the stack trace.

java.lang.IllegalArgumentException: calculated end index (2231) is out of
allowable range (2204..2228)
    at
org.apache.poi.util.LittleEndianByteArrayOutputStream.<init>(LittleEndianByteArrayOutputStream.java:41)
    at
org.apache.poi.hssf.record.StandardRecord.serialize(StandardRecord.java:45)
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook$SheetRecordCollector.serialize(HSSFWorkbook.java:1259)
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1305)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1205)
    at Test1.main(Test1.java:13)


I looked into the source code and found that method
org.apache.poi.hssf.model.InternalWorkbook#removeSheet(int) destroys the
consistency of internal data.

Here is part of the source code in that method.

        if (boundsheets.size() > sheetIndex) {
            records.remove(records.getBspos() - (boundsheets.size() - 1) +
sheetIndex);
            boundsheets.remove(sheetIndex);
            fixTabIdRecord();
        }

The code is intended to remove the same instance from both of fields
"boundsheets" and "records".
This works only if the orders of elements are the same in both fields, but once
method setSheetOrder(String, int) is called, only "boundsheets" is reordered
and the precondition is not valid anymore.

This causes different result in calculating the size of the serialized data
between method InternalWorkbook#serialize(int, byte[]) and
InternalWorkbook#getSize() (returns wrong result).
When getSize() returns a value less than the true serialized data size, POI
fails to allocate enough size of buffer and the exception shown above occurs.

I will attach a zip file including a test code and a patch to fix the bug.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 53147] Reordering and removing sheet causes internal data inconsistency

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53147

recyclebin5385@yahoo.co.jp changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #1 from recyclebin5385@yahoo.co.jp 2012-04-26 13:20:48 UTC ---


*** This bug has been marked as a duplicate of bug 50083 ***

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 53147] Reordering and removing sheet causes internal data inconsistency

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53147

recyclebin5385@yahoo.co.jp changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|PC                          |All
            Version|unspecified                 |3.8
         OS/Version|Windows Vista               |All

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org