Bug 58805 - Header and footer corruption on Run text replacement
Summary: Header and footer corruption on Run text replacement
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: HWPF (show other bugs)
Version: 3.13-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-05 14:13 UTC by Thomas Schwery
Modified: 2016-01-05 14:13 UTC (History)
0 users



Attachments
Input file with header and footer tests (27.50 KB, application/msword)
2016-01-05 14:13 UTC, Thomas Schwery
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwery 2016-01-05 14:13:26 UTC
Created attachment 33407 [details]
Input file with header and footer tests

The header and footer of doc documents can become corrupted and either crash Word or present wrong header and footers in the resulting document when runs have their text replaced.

The attached document is used as a template by the following code that will replace placeholders with a new text content :

        HWPFDocument doc = new HWPFDocument(new FileInputStream(tstFile));
        
        Range oRange = doc.getHeaderStoryRange();
        for (int i = 0; i < oRange.numCharacterRuns(); i++) {
            CharacterRun run = oRange.getCharacterRun(i);
            run.replaceText("_TEST_", "This text is longer than the initial text. It goes on and on without interruption.");
        }
        
        FileOutputStream fos = new FileOutputStream(outFile);
        doc.write(fos);
        fos.close();

The resulting file displays only part of the text in the header and the footer is copied from the header and cannot be edited when opened in Word 2013. LibreOffice 5 displays a short text in the header and copies the table in the footer with only a small snippet of text.
The _TEST_ in the main part of the document is not replaced, which is as expected.