Bug 58804

Summary: Broken images depending on Layout options
Product: POI Reporter: Thomas Schwery <thomas.schwery>
Component: HWPFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 3.13-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Input file with 12 test pictures
Input file with a single picture

Description Thomas Schwery 2016-01-05 09:04:36 UTC
Created attachment 33405 [details]
Input file with 12 test pictures

If a document contains a number of images with "Layout" options different from "Inline with text", they are missing from the output document.

Attached is a document with 12 sample images with different layouts :
- First row has 3 images "Inline with text". They are kept after save
- Second and third row have images with different text alignments Square, Tight, Through, Top/Bottom, Behind and In front of text. These are lost after save.
- Fourth row has the same images as first row. They are kept after save.

The Java code to reproduce the error only needs to open the file and save it, without modifications :
        HWPFDocument doc = new HWPFDocument(new FileInputStream(inFile));
        FileOutputStream fos = new FileOutputStream(outFile);
Comment 1 Thomas Schwery 2016-01-05 09:06:31 UTC
Created attachment 33406 [details]
Input file with a single picture

The image is also lost if it is alone in the document.
Comment 2 Thomas Schwery 2016-01-19 15:15:52 UTC
The following testcase illustrates the problem :

    public void testImageCountLayout() throws Exception {
        HWPFDocument docA = HWPFTestDataSamples.openSampleFile("Bug58804-picture_single.doc");

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        HWPFDocument docB = new HWPFDocument(new ByteArrayInputStream(out.toByteArray()));


        PicturesTable picA = docA.getPicturesTable();
        PicturesTable picB = docB.getPicturesTable();

        List<Picture> picturesA = picA.getAllPictures();
        List<Picture> picturesB = picB.getAllPictures();

        assertEquals(1, picturesA.size());
        assertEquals(1, picturesB.size());

In this case, the test fails because picturesB is empty where it should be 1.
Comment 3 Dominik Stadler 2016-01-25 20:21:56 UTC
I tried to take a look, but could not dig deep enough here, there is however now an ignored unit test in TestPictures as of r1726681 which reproduces this problem.