POI fails to read in the EndSubRecord. It has an sid of 0, which RecordInputStream treats as end of stream, so the EndSubRecord never gets added to its parent ObjRecord. Therefore on writing it is not serialized, resulting in a corrupt file. Patch and example workbook to follow.
Created attachment 17639 [details] Simple workbook to trigger bug. 1. Read in as HSSFWorkbook. 2. Serialize to file. 3. Open file in Excel. 4. Observe corruption.
Created attachment 17640 [details] Test and proposed fix for bug. Bug fix takes most direct route, perhaps it would be better to refactor LittleEndian to make EOF more obvious.
Created attachment 17643 [details] Updated fix. Discovered 0-padding of workbooks and revised patch accordingly. All tests now pass.
I've not looked at the workbook attached to the other bug but it seems like this bug is related to BUG#35527 The fix for BUG#35527 is commented out in the current codebase (presumably during the refactor to use RecordInputStream).
Fixed *** This bug has been marked as a duplicate of 41242 ***