Skip to content

vtamara/prob-excel-rspreadsheet03

Repository files navigation

Simple test that shows regression in rspreadsheet 0.3 and 0.4.1, that generates spreadsheets that cannot be opened with Excel.

The problem

Try to open min2.ods with Excel (2013 and 2016), it will fail as shown in screenshot excel2016.png

It will open correctly with LibreOffice. However the original file min.ods will open with Excel (sometimes with a warning, but it will open).

This behavior didn't occurr with rspreadsheet 0.2.14 (you can try with min2-0.2.14.ods that was created using rspreadsheet 0.2.14), it appeared with rspreadsheet 0.3 and is still present in current version 0.4.1

To generate the problematic file min2.ods from min.ods, clone this repository and then:

bundle install
bundle exec ruby prob.rb

The ruby script prob.rb will use rspreadsheet to open the file min.ods, change one cell and then it will create the file min2.ods.

Going deeper into the problem

The file min2-0.2.14.ods was generated by this application after changing in Gemfile

gem 'rspreadsheet', '0.3'

with

gem 'rspreadsheet', '0.2.14'

and running:

bundle install
bundle exec ruby prob.rb
mv min2.ods min2-0.2.14.ods

The file generated with rspreadsheet 0.3 and the one generated with 0.2.14 were uncompressed and compared, the result is:

$ mkdir 0.3
$ cd 0.3
$ unzip ../min2.ods
Archive:  ../min2.ods
 extracting: mimetype
 extracting: Thumbnails/thumbnail.png
  inflating: settings.xml
  inflating: content.xml
  inflating: styles.xml
  inflating: meta.xml
  inflating: manifest.rdf
   creating: Configurations2/toolpanel/
   creating: Configurations2/progressbar/
   creating: Configurations2/toolbar/
  inflating: Configurations2/accelerator/current.xml
   creating: Configurations2/images/Bitmaps/
   creating: Configurations2/popupmenu/
   creating: Configurations2/statusbar/
   creating: Configurations2/menubar/
   creating: Configurations2/floater/
  inflating: META-INF/manifest.xml

$ mkdir ../0.2.14
$ cd ../0.2.14
$ unzip ../min2-0.2.14.ods

Archive:  ../min2-0.2.14.ods
 extracting: mimetype
 extracting: Thumbnails/thumbnail.png
  inflating: settings.xml
  inflating: content.xml
  inflating: styles.xml
  inflating: meta.xml
  inflating: manifest.rdf
   creating: Configurations2/toolpanel/
   creating: Configurations2/progressbar/
   creating: Configurations2/toolbar/
  inflating: Configurations2/accelerator/current.xml
   creating: Configurations2/images/Bitmaps/
   creating: Configurations2/popupmenu/
   creating: Configurations2/statusbar/
   creating: Configurations2/menubar/
   creating: Configurations2/floater/
  inflating: META-INF/manifest.xml

$ cd ..
$ diff -r 0.2.14/ 0.3/
diff -r 0.2.14/META-INF/manifest.xml 0.3/META-INF/manifest.xml
12c12
< </manifest:manifest>
\ No newline at end of file
---
> </manifest:manifest>

Checking sizes of manifest.xml:

0.2.14/META-INF/manifest.xml: 1093
0.3/META-INF/manifest.xml: 1094

The tail of the hexdump of each one is

0.2.14/META-INF/manifest.xml: 

00000420  63 6f 6e 66 69 67 75 72  61 74 69 6f 6e 22 2f 3e  |configuration"/>|
00000430  0a 3c 2f 6d 61 6e 69 66  65 73 74 3a 6d 61 6e 69  |.</manifest:mani|
00000440  66 65 73 74 3e                                    |fest>|
00000445


0.3/META-INF/manifest.xml: 

00000420  63 6f 6e 66 69 67 75 72  61 74 69 6f 6e 22 2f 3e  |configuration"/>|
00000430  0a 3c 2f 6d 61 6e 69 66  65 73 74 3a 6d 61 6e 69  |.</manifest:mani|
00000440  66 65 73 74 3e 0a                                 |fest>.|
00000446

So the only difference was an additional CR (0x0a) at the end of 0.3/META-INF/manifest.xml This shouldn't be a problem since XML allows this (https://www.w3.org/TR/REC-xml/).

We compressed back the file produced by rspreadsheet 0.3:

cd 0.3
rm -f ../min2-0.3-mod.ods
zip ../min2-0.3-mod.ods -Z store mimetype
zip ../min2-0.3-mod.ods -Z store Thumbnails/thumbnail.png
zip ../min2-0.3-mod.ods -Z deflate settings.xml content.xml styles.xml meta.xml manifest.rdf
zip ../min2-0.3-mod.ods -Z store Configurations2/toolpanel/
zip ../min2-0.3-mod.ods -Z store Configurations2/progressbar/
zip ../min2-0.3-mod.ods -Z store Configurations2/toolbar/
zip ../min2-0.3-mod.ods -Z deflate Configurations2/accelerator/current.xml
zip ../min2-0.3-mod.ods -Z store Configurations2/images/Bitmaps/
zip ../min2-0.3-mod.ods -Z store Configurations2/popupmenu/
zip ../min2-0.3-mod.ods -Z store Configurations2/statusbar/
zip ../min2-0.3-mod.ods -Z store Configurations2/menubar/
zip ../min2-0.3-mod.ods -Z store Configurations2/floater/
zip ../min2-0.3-mod.ods -Z deflate META-INF/manifest.xml
cd ..

The resulting mod2-0.3-mod.ods could be opened with Excel, so we conclude that there should be a problem in the compression of the file generated by rspreadsheet.

Trying to fix the regression

Analyzing the sources of rspreadsheet, we find the compression and saving in lib/rspreadsheet/workbook.rb.

The function update_manifest_and_content_xml(input_zip,output_zip) updates the compressed files: content.xml and META-INFO/manifest.xml. Updating the manifest file is done by update_manifest_xml(input_zip,output_zip) that besides adds images required to the zipfile and to the manifest file (although the example we are using doesn't have images).

About

Showing regression in rspreasheet 0.3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages