axlsx icon indicating copy to clipboard operation
axlsx copied to clipboard

Corrupted files can be generated when worksheet names of a certain length contain unicode

Open aardvarkk opened this issue 7 years ago • 0 comments

Can be reproduced with the following example:

require 'axlsx'

Axlsx::Package.new do |p|
  p.workbook.add_worksheet(:name => "good")
  p.serialize('good.xlsx')
end

Axlsx::Package.new do |p|
  p.workbook.add_worksheet(:name => "\u{1F1EB 1F1F7}1234567890123456789012345678")
  p.serialize('bad.xlsx')
end

The file good.xlsx works fine. The file bad.xlsx displays an error upon opening in Microsoft Excel and asks to repair a corrupted file.

The root cause seems to be the 31 character worksheet name limit. When unicode is used in the worksheet name, the additional bytes don't seem to count toward the 31 character limit. So in this case, a 28- or 29- character "normal" string (after the unicode portion) will not throw an error but will generate a corrupted file. I would recommend updating the error trigger on a too-long name to check string length in bytes instead of just normal string length.

aardvarkk avatar May 25 '18 22:05 aardvarkk