https://issues.apache.org/bugzilla/show_bug.cgi?id=51815
Triqui <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEEDINFO |NEW --- Comment #3 from Triqui <[email protected]> --- I'm adding this comment because I've found this problem in a number of documents, and I think POI could handle this error a bit better. And I think the same error is showing in the document attached for bug 50833. The question seems to be that when the WriteAccessRecord finds a corrupt header tries to reconstruct the data for the last document modification and tries to set the username. But sometimes fail. I've seen the code and found a comment which states that this information is optional: // String header looks wrong (probably missing) // OOO doc says this is optional anyway. // reconstruct data So I wonder if it could be possible to catch the exception thrown by the setUsername method and just clear the username in that case. I've been testing with LibreOffice and Excel 2003 and they ignore that information in any document with this problem. Something like this could solve the problem: public WriteAccessRecord(RecordInputStream in) { ... if (nChars > DATA_SIZE || (is16BitFlag & 0xFE) != 0) { // String header looks wrong (probably missing) // OOO doc says this is optional anyway. // reconstruct data byte[] data = new byte[3 + in.remaining()]; LittleEndian.putUShort(data, 0, nChars); LittleEndian.putByte(data, 2, is16BitFlag); in.readFully(data, 3, data.length-3); String rawValue = new String(data); try { setUsername(rawValue.trim()); } catch (IllegalArgumentException e) { setUsername(""); // or just log a warning and skip it } return; } ... } I don't know if there is a better way of handling corrupted data, but if that bit of info is optional, I think no exception should be thrown. Please, let me know what you think. * I attached results from ms biffvalidator and poi biffviewer, I cannot attach a real document since it contains sensible information and when I try to modify it and save the problem goes away. But let me know if you really need it and I will see what I can do. * Just in case, the "data" byte array final value is: [5, 63, 63, 63, -122, ... (till index 55), 32, ... (till index 111)] -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
