Bug 58804 - Broken images depending on Layout options
Summary: Broken images depending on Layout options
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
Depends on:
Reported: 2016-01-05 09:04 UTC by Thomas Schwery
Modified: 2016-01-25 20:21 UTC (History)
0 users

Input file with 12 test pictures (299.50 KB, application/msword)
2016-01-05 09:04 UTC, Thomas Schwery
Input file with a single picture (60.00 KB, application/msword)
2016-01-05 09:06 UTC, Thomas Schwery

Note You need to log in before you can comment on or make changes to this bug.
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.