miachm / SODS

A simple Java library for handle ODS (Open Document Spreadsheet, compatible with Excel and Libreoffice)
The Unlicense
74 stars 30 forks source link

Regression: LibreOffice complains about corrupt file from MRE #55

Closed LoadingByte closed 1 year ago

LoadingByte commented 1 year ago

Consider this minimal reproducible example:

public class Main {
    public static void main(String[] args) throws IOException {
        Sheet sheet = new Sheet("Test", 3, 2);
        sheet.getDataRange().setValues(1, 2, 3, 4, 5, 6);
        SpreadSheet spread = new SpreadSheet();
        spread.appendSheet(sheet);
        spread.save(new File("/path/to/output.ods"));
    }
}

On version 1.4.0, this produces a file that LibreOffice 7.3.7.2 (latest STILL version, build from the Arch Linux repository) can read without any issues. From version 1.5.0 onward however (i.e., including 1.5.1 and 1.5.2), LibreOffice complains with the following message:

The file 'MRE.ods' is corrupt and therefore cannot be opened. LibreOffice can try to repair the file.

The corruption could be the result of document manipulation or of structural document damage due to data transmission.

We recommend that you do not trust the content of the repaired document. Execution of macros is disabled for this document.

Should LibreOffice repair the file?

Clicking "Yes" then succeeds in opening the allegedly damaged file. While this technically works, it's of course not good user experience, so we're currently blocked from upgrading past SODS 1.4.0.

Unpacking and diffing two ODS files generated by the above MRE with SODS 1.4.0 and 1.5.0 respectively shows that there are just two differences between the two versions:

  1. In content.xml, 1.4.0 writes <table:table-column></table:table-column><table:table-column></table:table-column>, while 1.5.0 writes <table:table-column table:number-columns-repeated="2"></table:table-column>.
  2. 1.5.0 writes a new file styles.xml which contains <?xml version="1.0" encoding="UTF-8"?><office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.2"></office:document-styles>. SODS 1.4.0 does not write this file.

Manually reverting each of these differences individually in the ODS file generated by SODS 1.5.0 shows that difference 2 is single-handedly responsible for the error message, as deleting the file from the archive gets rid of the error.

Sadly, I'm neither an expert on the ODS format nor have I managed to extract useful logging information from LibreOffice that would shine some light on why exactly this hiccup happens. Still, I hope you can reproduce this issue and have enough information to be able to fix it.

Thanks for sharing this handy library and all the best, Felix

github-actions[bot] commented 1 year ago

Thanks for your report! Please ensure you have provided enough info in order to recreate the issue, including the problematic ODS File.

miachm commented 1 year ago

@LoadingByte the second change was introduced for solving another issue in Microsoft Excel. Which expects a styles.xml in the file. Not sure why Libre Office does not like it!

It should be easy to reproduce. But I guess the problem is caused because styles.xml is not present in the manifests file (META-INF/manifest.xml). I'll take a look into this later in my computer

LoadingByte commented 1 year ago

You're totally right. Adding a manifest entry for styles.xml turns out to fix the issue.

LoadingByte commented 1 year ago

Could you maybe release a hotfix version that includes the fix prior to the new year? This bug is currently the last remaining blocker for the next release of my film credits suite "Cinecred", and I have some users waiting impatiently for the next version. I'd be very grateful :)

Best, Felix

LoadingByte commented 1 year ago

Sorry to bother you, but could you maybe give some rough ETA of when you will be able to publish the small fix to Maven Central? In case you don't have enough time on your hands right now, I'll just remain on 1.4.0—but if you plan on releasing over the next few days anyway, I'd like to avoid prematurely pushing a new version to my users.

Thanks in advance, Felix

miachm commented 1 year ago

Sorry abroad for holidays! It's going to take a while until I am able to create a proper release.

I uploaded a quick fix and I created a staging release: v1.5.3-staging. Let's me know if you can use it.

LoadingByte commented 1 year ago

No worries, we all need some rest after last year!

Thanks a lot for the fix. I generally prefer to include only artifacts archived on Maven Central in releases though to ensure future reproducibility of the build, so seeing as the next release of SODS will take some time, I'll probably ship with SODS 1.4.0 for now and then upgrade later on. It's unlikely that many users will come across the Excel issues in the meantime, I presume.

Thanks again for your heads-up and support even during your holidays! Felix

sdaschner commented 1 year ago

I have the same issue, how exactly can I try the v1.5.3-staging version, i.e. which staging URL to add to my pom.xml?

Rattle22 commented 1 year ago

I've come across this issue as well, the documents I have tried modifing with 1.5.2 are identified as broken (but are fully restorable) by both Excel and LibreOffice. Additionally, some excel files saved as .ods appear to break "entirely" when modified with 1.5.2? I have example documents if those help. It's not a huge issue, I found workarounds and my client is fine with the broken documents for now, but an update to fix this would be hugely appreciated.

(Additionally the column and row sizes are way larger when opened with Excel than when opened with LibreOffice. I have no idea if that is a related issue.)

miachm commented 1 year ago

@Rattle22 @sdaschner @LoadingByte sorry for the delay, it is fixed in v1.5.3.

LoadingByte commented 1 year ago

Thank you a lot for the fix! I just verified that 1.5.3 indeed no longer provokes the error. So we can close this now :)

@Rattle22 I guess if your unrelated problems persist, you should probably open a new issue with more details.