Bug 88070 - FILESAVE: "The File could not be written" unable to save file with 3200+ comments
Summary: FILESAVE: "The File could not be written" unable to save file with 3200+ com...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.3.5.2 release
Hardware: IA64 (Itanium) Windows (All)
: medium major
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Calc-Comments GDI-Limit
  Show dependency treegraph
 
Reported: 2015-01-05 20:30 UTC by Jonathan Kreider
Modified: 2017-01-31 22:10 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
ODS file that won't save after copying the template page to a worksheet. (232.60 KB, application/vnd.oasis.opendocument.spreadsheet)
2015-01-05 20:31 UTC, Jonathan Kreider
Details
ODS as before but not password protected (230.70 KB, application/vnd.oasis.opendocument.spreadsheet)
2015-01-05 20:36 UTC, Jonathan Kreider
Details
Backtrace gdb when saving document with more than 3200 comments (8.55 KB, text/plain)
2016-06-09 14:29 UTC, Alexis PAQUIN
Details
GDI trouble backtrace (7.06 KB, text/plain)
2017-01-23 19:30 UTC, Arnaud Versini
Details
Backtrace of the problematic GDI creation (7.06 KB, text/plain)
2017-01-23 19:34 UTC, Arnaud Versini
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Kreider 2015-01-05 20:30:16 UTC
We have a payroll spreadsheet that won't save after we make changes to it.  It originated (years ago) in Quattro, was saved as an Excel spreadsheet(years ago) and now we would like to save it as an .ods file.  We CAN save it as an .ods file, but only after cutting out the vast majority of the data.  The file is less than 300k, so I don't think size is the issue.

I'm including two sample files: An .ods file that I managed to save and and excel file that I saved after I made some changes and FAILED to save as an ods file.

The platform is Windows7 64bit OS with 8GB of ram.  However, we've experienced this same problem on XP in the past.

To reproduce the problem, copy the contents of Template Hourly 2 into one of the employees sheets and try to save the file.
Comment 1 Jonathan Kreider 2015-01-05 20:31:22 UTC
Created attachment 111786 [details]
ODS file that won't save after copying the template page to a worksheet.
Comment 2 Jonathan Kreider 2015-01-05 20:36:18 UTC
Created attachment 111788 [details]
ODS as before but not password protected
Comment 3 raal 2015-01-06 13:14:39 UTC
Hello,
I can reproduce with 4.3.5.2, win7. 
I can copy data from "Template Hourly 2" into new sheet and save it without problems, so I think this bug should be closed as wontfix. As you wrote "It originated (years ago) in Quattro, was saved as an Excel spreadsheet(years ago) and now we would like to save it as an .ods file."
Are you able to copy data into new file if bug still occurs in new file?
Comment 4 Jonathan Kreider 2015-01-07 14:25:23 UTC
I've been able to reproduce the error from scratch in a blank calc document.  The issue seems to be related to the number of cells in spreadsheet that have comments.  I haven't found a consistent number EXACTLY, but somewhere between 3200 and 3300 comments in a spreadsheet will cause the file to not save as ODS.

This bug does not appear to be related to the number of characters of the comment field.  I've reproduced it with large comments and small comments at about the same number of total comments in the sheet.

To reproduce this bug: 
* Create a new calc document
* Create a comment in cell A1 such as "test comment".
* Copy this cell down through A3200 and save the file.
* Copy cell A1 from A3201 through A3300 and save the file.

You should get the error - "Error saving the document <MyDoc>:Write Error.  The file could not be written."
Comment 5 raal 2015-01-08 06:35:00 UTC
(In reply to Jonathan Kreider from comment #4)

> 
> To reproduce this bug: 
> * Create a new calc document
> * Create a comment in cell A1 such as "test comment".
> * Copy this cell down through A3200 and save the file.
> * Copy cell A1 from A3201 through A3300 and save the file.
> 
> You should get the error - "Error saving the document <MyDoc>:Write Error. 
> The file could not be written."

I can confirm with LO 4.3.5, win7.
Comment 6 Jonathan Kreider 2015-02-11 15:31:08 UTC
(In reply to raal from comment #5)
> (In reply to Jonathan Kreider from comment #4)
> 
> > 
> > To reproduce this bug: 
> > * Create a new calc document
> > * Create a comment in cell A1 such as "test comment".
> > * Copy this cell down through A3200 and save the file.
> > * Copy cell A1 from A3201 through A3300 and save the file.
> > 
> > You should get the error - "Error saving the document <MyDoc>:Write Error. 
> > The file could not be written."
> 
> I can confirm with LO 4.3.5, win7.

I've reconfirmed this bug with LO 4.4.0 win7
Comment 7 Jonathan Kreider 2015-07-10 16:12:38 UTC
Confirmed the bug still exists in 5.0.0.2 Windows X64
Comment 8 Alexis PAQUIN 2016-06-09 14:29:03 UTC
Created attachment 125573 [details]
Backtrace gdb when saving document with more than 3200 comments

Here is the backtrace when LO crash when save file
Comment 9 Alexis PAQUIN 2016-07-26 13:44:22 UTC
Hey,

I found some new informations on this bug.

I test with LO 5.0.6 and use Visual Studio 2013.

An exception is thrown on during the XML export, exactly on "content export" treatement in xmlwrap.cxx class.

This append on a specific note, the 3274th, on the 1627th row and 0 col.

The exception come from the class 
virdev.cxx, line 152, mpVirDev is valued with NULL.

The method whose return NULL is WinSalInstance::CreateVirtualDevice in salvd.cxx

The problem come from the hBmp variable, valued with NULL after the call of WinSalVirtualDevice::ImplCreateVirDevBitmap(pGraphics->getHDC(), nDX, nDY, nBitCount, &pDummy);


I hope this will be help

Best regards

Alexis
Comment 10 Alexis PAQUIN 2016-08-10 08:36:46 UTC
Hi,

I find a bypass for this issue.

With Win7, modify the key register GDIProcessHandleQuota  in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows. Set the value to 65536 (max value) and file can be save.

The default value was 10000, so it mean that LO use more than 10000 GDI objects when saving a file with more than 3200 comments and crash.

Best regards

Alexis
Comment 11 Arnaud Versini 2017-01-23 19:28:55 UTC
Hello everyone,

The problem is during saving, we create a GDI object for each comment, this is done by collectTextAutoStyles, wich call exportToText wich indirectly call CreateVirtualDevice. I'll put the complete backtrace in this bug.

I don't think the GDI object is necessary for the export, but I can't see a way to not create the GDI object, or to free it before the next comment.
Comment 12 Arnaud Versini 2017-01-23 19:30:51 UTC
Created attachment 130635 [details]
GDI trouble backtrace

This is the backtrace of the GDI allocation that causes this bug
Comment 13 Arnaud Versini 2017-01-23 19:34:05 UTC
Created attachment 130637 [details]
Backtrace of the problematic GDI creation
Comment 14 Kohei Yoshida 2017-01-26 02:35:33 UTC
I've tested it with a build that contains fix for Bug 103927, and I can't reproduce this problem.
Comment 15 Kohei Yoshida 2017-01-27 20:50:16 UTC
Someone please test and confirm this.  If not, I'll assume it is fixed.
Comment 16 Arnaud Versini 2017-01-29 15:27:35 UTC
I confirm, you fixed this commit ! Do you plan to backport this commit to 5.2 and 5.3 ? If not I can ?
Comment 17 Kohei Yoshida 2017-01-31 22:10:22 UTC
The backports are here:

5.3: https://gerrit.libreoffice.org/#/c/33640/
5.2: https://gerrit.libreoffice.org/#/c/33641/