https://bz.apache.org/bugzilla/show_bug.cgi?id=69667
Bug ID: 69667 Summary: WriteAccessRecord constructor setUsername throws IllegalArgumentException Product: POI Version: 5.4.1-FINAL Hardware: Macintosh Status: NEW Severity: blocker Priority: P2 Component: HSSF Assignee: dev@poi.apache.org Reporter: jason.sla...@ring-zero.com Target Milestone: --- I have an XLS file generated by Data Dynamics' SpreadBuilder. When I attempt to parse the file, it encounters a WriteAccessRecord and I am unable to proceed any further. In WriteAccessRecord constructor: - nChars is 81 and encoding is UTF-16LE. - it allocates a buffer of 109 bytes (DATA_SIZE-3) - it reads the data into the buffer - because it's UTF-16: - byteCnt = Math.min(nChars * 2, data.length) => 109, since it's the min of 81*2 (162) and 109 - however, when it goes to create a string from the buffer and trim it: - String rawValue = new String(data, 0, byteCnt, charset); <--- the resulting string has some garbage character(s) at the end. "Data Dynamics' SpreadBuilder �" - the garbage characters cause the trim() to have no effect, - so, when it gets to setUsername, the string is 55 characters long. Because it calculates encodedByteCount as length * 2 for this encoding, it throws an exception because 110 > 109 I believe the problem originates: if (nChars <= 109 && (is16BitFlag & 254) == 0) { data = IOUtils.safelyAllocate((long)in.remaining(), 109); in.readFully(data); if (UTF16FLAG.isSet(is16BitFlag)) { byteCnt = Math.min(nChars * 2, data.length); <-- **HERE** charset = StandardCharsets.UTF_16LE; } else { byteCnt = Math.min(nChars, data.length); charset = StandardCharsets.ISO_8859_1; } } else if (in.isEncrypted()) { because the byte count for UTF-16LE should always be an even number. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org