fernandreu / office-ribbonx-editor

An overhauled fork of the original Custom UI Editor for Microsoft Office, built with WPF
MIT License
516 stars 100 forks source link

Error Opening File: "End of Central Directory record could not be found" #150

Closed Alex-ley closed 3 years ago

Alex-ley commented 3 years ago

Describe the bug Error When Opening (large password protected .xlsm ~50k KB) File: "End of Central Directory record could not be found" (I don't get errors opening smaller/unprotected .xlsm files)

To Reproduce Steps to reproduce the behavior:

  1. Open the tool
  2. Click on "Open"
  3. Navigate to your large password-protected .xlsm file in the FileDialog and select it and click open
  4. See error included in the screenshot below (file doesn't open)

Expected behavior I'd expect the tool to open the file and allow me to edit the ribbon XML etc.

Screenshots image

Additional context Version: 1.8.0.990 Runtime: .NET 5.0.2 Operating System: Microsoft Windows 10.0.18363

Alex-ley commented 3 years ago

If I remove the password protection the file opens, so closing this issue. My appologies for the inconvenience.

fernandreu commented 3 years ago

No problem @Alex-ley. Modifying a password-protected file is actually an interesting use case, so I will investigate it a bit and determine whether it is feasible to support it from the tool as well.

Alex-ley commented 3 years ago

@fernandreu sounds good. Glad I sparked an idea then, potentially. I'm not sure how your tool actually works I never went through the code but my guess would be you convert the excel file to zip and then open the zip and modify the contents etc? Adding the CustomUI folder and xml file and the rels etc?

If this is the case, you may struggle to allow the opening of password protected files. The reason I say this is that I contributed to openpyxl (which reads/writes the file the same way, with zip and xml etc.) and they state that opening protected files is not supported. But I'd love to be wrong and if you do figure it out it would be interesting to see if that could be added to openpyxl as well. Although, you might end up using something from .NET (like Microsoft.Office.Interop.Excel) to help whereas openpyxl is pure python and wouldn't use something like that.

Either way I'd be curious to hear how it goes. Good luck!🍀

fernandreu commented 3 years ago

Yeah that's the case for the tool as well, it unzips the file, modifies the customUI, icons, etc., then zips it back. It's probably going to be as you say and stay unsupported. I did find the spec that describes their encryption system (here), but it seems rather complex, and easy to implement incorrectly (at least for somebody like me who's not used to deal with encryption at this level). There doesn't seem to be a nice Windows library or community-made NuGet package for this either.

I'll give it another thought once I have a bit more time, but it's very likely that I'll just end up detecting the case where it's encrypted so that the error message you see explains the situation a bit better.