Issue 127218

Summary: Renaming paragraph style in Writer destroys the document
Product: Writer Reporter: Elmar <elmar>
Component: editingAssignee: AOO issues mailing list <issues>
Status: CONFIRMED --- QA Contact:
Severity: Normal    
Priority: P5 (lowest) CC: mseidel, oooforum, petko, rkoorits, seclasse, sierra.midiaelena, szeto.calvin
Version: 4.1.3Keywords: data_loss
Target Milestone: ---   
Hardware: PC   
OS: Linux 64-bit   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---

Description Elmar 2016-11-20 07:00:16 UTC
If I change the name of a paragraph style in my document and then save it, a totally corrupted document is written to disk.

You can download the document to reproduce the problem here:
http://yasara6.cmbi.ru.nl/service/corruption.odt

Steps to reproduce (100% reproducible):

1.Load the document corruption.odt
2.Press F11 to bring up Styles+Formatting
3.Right-click on Style ITX, click Modify
4.Select the 'Organizer' tab, change name from ITX to ITX2, press <Tab> so that next style is also ITX2
5.Click Apply and OK
6.Click File > Save
7.Close and reopen the document 

Document is totally corrupted. Since the corruption is only visible after reopening, an entire day of work was affected even though auto-save was active.

The same problem happens in LibreOffice (sent them a report too), in CentOS 5, CentOS 6 and CentOS 7 64bit.
Comment 1 oooforum (fr) 2016-11-24 15:15:33 UTC
Not reproduce with AOO 4.1.3 and Win7 x64 Pro
Document looks fine after reopened
Comment 2 mroe 2016-11-24 16:05:55 UTC
(In reply to Elmar from comment #0)
> You can download the document to reproduce the problem here:
> http://yasara6.cmbi.ru.nl/service/corruption.odt

With this file and the given steps under Ubuntu 64 bit I can reproduce this issue as described. It seems that the file was original created with a version of Word, so maybe there is an import problem.
Comment 3 oooforum (fr) 2016-12-20 10:36:35 UTC
(In reply to mroe from comment #2)
> (In reply to Elmar from comment #0)
> It seems that the file was original created with a
> version of Word, so maybe there is an import problem.
Interresting
@Elmar: did you have the same problem with a new document?
Comment 4 Elmar 2016-12-20 12:40:41 UTC
(In reply to oooforum (fr) from comment #3)
> (In reply to mroe from comment #2)
> > (In reply to Elmar from comment #0)
> > It seems that the file was original created with a
> > version of Word, so maybe there is an import problem.
> Interresting
> @Elmar: did you have the same problem with a new document?

I tried to supply a minimal version of the document by deleting parts as long as the problem persisted. I figured that's what you need to reproduce and fix the bug. I didn't try with other documents, assuming that with 'new document' you mean 'other documents not imported from Microsoft Word'

Regards,
Elmar
Comment 5 Samantha Classen 2017-02-24 06:59:46 UTC
System: Windows 10 (64-bit)
Version: Apache Open Office 4.1.3

Following the provided steps, I was able to reproduce the issue described. When I reopened the document (step 7 of the original post), the document looked completely different from the original. A majority of the text and images did not retain its positioning. The two column layout was extended throughout the whole document (not present in initial document). So, as Elmar stated, the document became corrupted.

Although the typical user may not happen upon this issue (may not make use of paragraph styles and therefore would not be renaming them—disregarding the fact that there may be an import issue involved), those who do run into this issue may deem this product unusable.
Comment 6 Rasmus Koorits 2017-04-09 00:01:15 UTC
I was able to reproduce this issue from a blank file, without using import. Under specific conditions, Writer seems to forget the Style of a section of text.
The original sample file used a lot of graphs, frames, and styling, making the impact more severe.

It seems the Style is reset to 'Default' when the following critical conditions are met:
 1. A Custom Style needs to be used (since others cannot be renamed)
 2. Style information has to be overridden in the actual text (for example using a style with regular font weight, but setting the text to bold everywhere with ctrl+b)
 3. The used Style has to be renamed
 4. The file is saved, closed, and reopened.

Steps to reproduce:
-Creating the file:
 1. Open a new blank document

-Create a new style:
 2. Press F11 to bring up 'Styles and Formatting'
 3. Be on the 'Paragraph Styles' tab (only tested with these so far)
 4. Find and select the 'Default' style (only tested with this one so far)
 5. Click 'New Style From Selection'
 6. Name the style something meaningful. I named it 'corruptionTest'.
 7. Click OK

-Back to the main document body:
 8. Write some text into the blank document.
 9. Apply the newly created style to it (should be automatically applied since this style is selected)
 10. Select ALL the text and set text to bold (ctrl+b), thus overriding the font weight of the style that was just created. (Interestingly, the issue does NOT occur when only part of the text is bolded)

-Back to 'Styles and Formatting' window:
11. Right-click on the newly created style, click Modify
12. Select the 'Organizer' tab, change name to something else. I changed it to 'corruptionTest2'.
13. Click 'Ok'
14. File > Save (Or Ctrl+S)
15. Close and reopen the document

Expected:
Text should be bold and using the newly created Style

Observed:
Text is no longer bold and using the Style 'default'

System: Windows 10 (64-bit)
Version: Apache Open Office 4.1.3, and 4.2.0 (nightly en-US_1785175)
Comment 7 Midia Elena Sierra Dumitrescu 2017-09-30 21:28:31 UTC
Midia Sierra (30/09/2017)

I would like to add a few things to this last comment from @Rasmus Koorits.

Following the same steps that he described, I could reproduce this bug:
1- With other style types of Paragraph style, not only with Default Style (step 4). I tested also with Caption, Drawing, Header, Addressee, and I could reproduce the bug. 
2- The bug is not triggered only by changing ALL TEXT TO BOLD. It’s also triggered if: (step 10)
-	you change the text to bold, italic, underling, font color, highlighting, the align (those where the changes I did)
-	Second important is that you don’t have to make the change to ALL TEXT. The smallest unit of text that you need to change to trigger the problem is a paragraph. You can change at list 1, or many paragraphs. If you change for example, after you have applied the paragraph style to the whole text (3 paragraphs) and then you make some changes to paragraph 1 and 3 (1 being highlighted and 3 being underlying), change the name of the style, save, and reopen the document, you will find that the paragraph 1 and 3 are in style type Default, and paragraph 2 (who was not changed) is in the style that you previously assigned before closing. 
If you on the other hand change a sentence of a paragraph and follow the steps, you wont get the bug. 
3- I confirm that only happened with Paragraph style. I couldn’t reproduce it with the rest of styles independently or in combination (Character style, Frame style, Page styles, List styles) (step 3)
4- When I edited the name I didn’t only used category Custom Style, I also used Special styles, Text style, Chapter style. (Point 1 of critical conditions part)

I did the tests on:
-  Version of Open Office 4.1.3 
- PC: MacBook Pro (Retina, 13-inch, Early 2015)
- Operating system: MacOs Sierra. Version 10.12.6
Comment 8 Midia Elena Sierra Dumitrescu 2017-09-30 22:20:19 UTC
I also could reproduce the bug following the first steps of the first description of Elmar in:
-  Version of Open Office 4.1.3 
- PC: MacBook Pro (Retina, 13-inch, Early 2015)
- Operating system: MacOs Sierra. Version 10.12.6
Comment 9 Calvin 2019-05-11 14:55:17 UTC
I was able to replicate this issue on two configurations (macOS Mojave and Windows 10). Further, I was able to spot the issue reflected in the unzipped ODT file.

Configurations:
macOS Version 10.14.4
OpenOffice 4.1.6
AOO416m1(Build:9790)  -  Rev. 1844436
2018-10-22 14:11:36 (Mon, 22 Oct 2018) - Darwin x86_64

Windows 10 Version 1803 OS build 17134.706
OpenOffice 4.5.0
AOO450m1(Build:9900) - Rev. 1858450
Rev.1858450

Replication Steps:
1. Create a blank document
2. Create three paragraphs (specifically, three separate lines saying “Line of text”)
3. Open the Styles and Formatting tab (F11 or Command+T)
4. Apply a different style A, B, and C to each of the three paragraphs (by dragging the paragraph into the Styles and Formatting tab, or clicking New Style from Selection)
5. Save as ODT file
6. Select the entirety of the lines styled by A and B, and apply the Italic property (through Properties or Command/Control+I)
7. Save
8. Rename style A to D (see previous comments for detailed instructions)
9. Save

In steps 5, 7 and 9, I unzipped the ODT file and observed the content.xml file. The files can be observed here: https://gist.github.com/calvinszeto/3ceb211536a6177a9329f43d0d7086ae.

In step 5 (content-1.xml: https://gist.github.com/calvinszeto/3ceb211536a6177a9329f43d0d7086ae#file-content-1-xml), you can see how styles are applied to paragraphs on lines 18, 20 and 22 by the attribute text:style-name="A".

In step 7, (content-2.xml: https://gist.github.com/calvinszeto/3ceb211536a6177a9329f43d0d7086ae#file-content-2-xml), you can see how a property is applied to an entire paragraph which also has a style. OpenOffice creates an automatic style (lines 10, 13) whose parent is the paragraph’s original style (style:parent-style-name="A"), and with the overriding property added (in this case, italic). The automatic style replaces the previous style (lines 25, 27).

In step 9, (content-3.xml: https://gist.github.com/calvinszeto/3ceb211536a6177a9329f43d0d7086ae#file-content-3-xml), you can see that line 26, originally with style A and later with style P1, has no style name attached to it. Line 27 has a style named P2 attached to it, and line 29 has style named C attached to it. Further, you can see in the automatic styles (line 10, 13) that P1 is still an italic style applied on top of parent style named A, and P2 is an italic style applied on top of parent style named B.

With no background in ODT/OpenOffice development, I can surmise based solely on the content.xml examples shown that when applying a property to an entire paragraph that already has a style attached to it, OpenOffice creates an automatic style with the original style as it’s parent and the new property as a style property (see how style P2 is applied to the line formerly styled as B). However, when renaming a style, OpenOffice is not correspondingly renaming the parent styles of any automatic styles (see how style P1 still has parent style A), and further, removes any automatic styles which had the original style as it’s parent (see how style P1 is removed from the first line).

Finally, I was also able to replicate the notes by Midia Elena Sierra Dumitrescu:
* only replicable with Paragraph Styles
* affected by any properties applied on an entire paragraph 
* does not affect other paragraphs with the same style, if there is not an additional property applied to them
Comment 10 Peter 2019-05-12 03:07:36 UTC
confirming based on the last 2 reports