View | Details | Raw Unified | Return to bug 35928
Collapse All | Expand All

(-)src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java (-5 / +5 lines)
Lines 590-598 Link Here
590
590
591
                    writer.processPOIFSWriterEvent(
591
                    writer.processPOIFSWriterEvent(
592
                        new POIFSWriterEvent(dstream, path, name, size));
592
                        new POIFSWriterEvent(dstream, path, name, size));
593
                    dstream.writeFiller(countBlocks()
593
                    dstream.writeFiller(countBlocks() *
594
                                        * POIFSConstants
594
                                            POIFSFileSystem
595
                                            .BIG_BLOCK_SIZE, DocumentBlock
595
                                            .getBigBlockSize(), DocumentBlock
596
                                            .getFillByte());
596
                                            .getFillByte());
597
                }
597
                }
598
                else
598
                else
Lines 617-624 Link Here
617
            {
617
            {
618
                if (writer != null)
618
                if (writer != null)
619
                {
619
                {
620
                    rval = (size + POIFSConstants.BIG_BLOCK_SIZE - 1)
620
                    rval = (size + POIFSFileSystem.getBigBlockSize() - 1)
621
                           / POIFSConstants.BIG_BLOCK_SIZE;
621
                           / POIFSFileSystem.getBigBlockSize();
622
                }
622
                }
623
                else
623
                else
624
                {
624
                {
(-)src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java (-2 / +24 lines)
Lines 55-60 Link Here
55
    private List          _documents;
55
    private List          _documents;
56
    private DirectoryNode _root;
56
    private DirectoryNode _root;
57
57
58
    private static int bigBlockSize = POIFSConstants.BIG_BLOCK_SIZE;
59
60
58
    /**
61
    /**
59
     * Constructor, intended for writing
62
     * Constructor, intended for writing
60
     */
63
     */
Lines 79-89 Link Here
79
    {
82
    {
80
        this();
83
        this();
81
84
85
        // check the big block size in the file
86
        PushbackInputStream pbis = new PushbackInputStream(stream, 64);
87
        byte[] b = new byte[31];
88
        pbis.read(b);
89
90
        if (b[30] == 12) bigBlockSize = POIFSConstants.ALT_BIG_BLOCK_SIZE;
91
92
        pbis.unread(b);
93
94
        
82
        // read the header block from the stream
95
        // read the header block from the stream
83
        HeaderBlockReader header_block_reader = new HeaderBlockReader(stream);
96
        HeaderBlockReader header_block_reader = new HeaderBlockReader(pbis);
84
97
85
        // read the rest of the stream into blocks
98
        // read the rest of the stream into blocks
86
        RawDataBlockList  data_blocks         = new RawDataBlockList(stream);
99
        RawDataBlockList  data_blocks         = new RawDataBlockList(pbis);
87
100
88
        // set up the block allocation table (necessary for the
101
        // set up the block allocation table (necessary for the
89
        // data_blocks to be manageable
102
        // data_blocks to be manageable
Lines 290-295 Link Here
290
    }
303
    }
291
304
292
    /**
305
    /**
306
     * get the size of a big block
307
     *
308
     * @return size of a big block
309
     */
310
    public static int getBigBlockSize() {
311
        return bigBlockSize;
312
    }
313
314
    /**
293
     * get the root entry
315
     * get the root entry
294
     *
316
     *
295
     * @return the root entry
317
     * @return the root entry
(-)src/java/org/apache/poi/poifs/storage/PropertyBlock.java (-1 / +2 lines)
Lines 23-28 Link Here
23
import java.util.*;
23
import java.util.*;
24
24
25
import org.apache.poi.poifs.common.POIFSConstants;
25
import org.apache.poi.poifs.common.POIFSConstants;
26
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
26
import org.apache.poi.poifs.property.Property;
27
import org.apache.poi.poifs.property.Property;
27
import org.apache.poi.util.IntegerField;
28
import org.apache.poi.util.IntegerField;
28
import org.apache.poi.util.LittleEndian;
29
import org.apache.poi.util.LittleEndian;
Lines 38-44 Link Here
38
    extends BigBlock
39
    extends BigBlock
39
{
40
{
40
    private static final int _properties_per_block =
41
    private static final int _properties_per_block =
41
        POIFSConstants.BIG_BLOCK_SIZE / POIFSConstants.PROPERTY_SIZE;
42
        POIFSFileSystem.getBigBlockSize() / POIFSConstants.PROPERTY_SIZE;
42
    private Property[]       _properties;
43
    private Property[]       _properties;
43
44
44
    /**
45
    /**
(-)src/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java (-1 / +2 lines)
Lines 19-24 Link Here
19
package org.apache.poi.poifs.storage;
19
package org.apache.poi.poifs.storage;
20
20
21
import org.apache.poi.poifs.common.POIFSConstants;
21
import org.apache.poi.poifs.common.POIFSConstants;
22
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
22
import org.apache.poi.util.IntegerField;
23
import org.apache.poi.util.IntegerField;
23
import org.apache.poi.util.LittleEndian;
24
import org.apache.poi.util.LittleEndian;
24
import org.apache.poi.util.LittleEndianConsts;
25
import org.apache.poi.util.LittleEndianConsts;
Lines 36-42 Link Here
36
    public static final long _signature               = 0xE11AB1A1E011CFD0L;
37
    public static final long _signature               = 0xE11AB1A1E011CFD0L;
37
    public static final int  _bat_array_offset        = 0x4c;
38
    public static final int  _bat_array_offset        = 0x4c;
38
    public static final int  _max_bats_in_header      =
39
    public static final int  _max_bats_in_header      =
39
        (POIFSConstants.BIG_BLOCK_SIZE - _bat_array_offset)
40
        (POIFSFileSystem.getBigBlockSize() - _bat_array_offset)
40
        / LittleEndianConsts.INT_SIZE;
41
        / LittleEndianConsts.INT_SIZE;
41
42
42
    // useful offsets
43
    // useful offsets
(-)src/java/org/apache/poi/poifs/storage/HeaderBlockWriter.java (-1 / +2 lines)
Lines 23-28 Link Here
23
import java.util.*;
23
import java.util.*;
24
24
25
import org.apache.poi.poifs.common.POIFSConstants;
25
import org.apache.poi.poifs.common.POIFSConstants;
26
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
26
import org.apache.poi.util.IntegerField;
27
import org.apache.poi.util.IntegerField;
27
import org.apache.poi.util.LittleEndianConsts;
28
import org.apache.poi.util.LittleEndianConsts;
28
import org.apache.poi.util.LongField;
29
import org.apache.poi.util.LongField;
Lines 65-71 Link Here
65
66
66
    public HeaderBlockWriter()
67
    public HeaderBlockWriter()
67
    {
68
    {
68
        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
69
        _data = new byte[ POIFSFileSystem.getBigBlockSize() ];
69
        Arrays.fill(_data, _default_value);
70
        Arrays.fill(_data, _default_value);
70
        new LongField(_signature_offset, _signature, _data);
71
        new LongField(_signature_offset, _signature, _data);
71
        new IntegerField(0x08, 0, _data);
72
        new IntegerField(0x08, 0, _data);
(-)src/java/org/apache/poi/poifs/storage/BATBlock.java (-2 / +3 lines)
Lines 24-29 Link Here
24
import java.util.Arrays;
24
import java.util.Arrays;
25
25
26
import org.apache.poi.poifs.common.POIFSConstants;
26
import org.apache.poi.poifs.common.POIFSConstants;
27
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
27
import org.apache.poi.util.IntegerField;
28
import org.apache.poi.util.IntegerField;
28
import org.apache.poi.util.LittleEndian;
29
import org.apache.poi.util.LittleEndian;
29
import org.apache.poi.util.LittleEndianConsts;
30
import org.apache.poi.util.LittleEndianConsts;
Lines 39-45 Link Here
39
    extends BigBlock
40
    extends BigBlock
40
{
41
{
41
    private static final int  _entries_per_block      =
42
    private static final int  _entries_per_block      =
42
        POIFSConstants.BIG_BLOCK_SIZE / LittleEndianConsts.INT_SIZE;
43
        POIFSFileSystem.getBigBlockSize() / LittleEndianConsts.INT_SIZE;
43
    private static final int  _entries_per_xbat_block = _entries_per_block
44
    private static final int  _entries_per_xbat_block = _entries_per_block
44
                                                            - 1;
45
                                                            - 1;
45
    private static final int  _xbat_chain_offset      =
46
    private static final int  _xbat_chain_offset      =
Lines 54-60 Link Here
54
55
55
    private BATBlock()
56
    private BATBlock()
56
    {
57
    {
57
        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
58
        _data = new byte[ POIFSFileSystem.getBigBlockSize() ];
58
        Arrays.fill(_data, _default_value);
59
        Arrays.fill(_data, _default_value);
59
        _fields = new IntegerField[ _entries_per_block ];
60
        _fields = new IntegerField[ _entries_per_block ];
60
        int offset = 0;
61
        int offset = 0;
(-)src/java/org/apache/poi/poifs/storage/SmallDocumentBlock.java (-14 / +19 lines)
Lines 23-28 Link Here
23
import java.util.*;
23
import java.util.*;
24
24
25
import org.apache.poi.poifs.common.POIFSConstants;
25
import org.apache.poi.poifs.common.POIFSConstants;
26
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
26
27
27
/**
28
/**
28
 * Storage for documents that are too small to use regular
29
 * Storage for documents that are too small to use regular
Lines 38-44 Link Here
38
    private static final byte _default_fill         = ( byte ) 0xff;
39
    private static final byte _default_fill         = ( byte ) 0xff;
39
    private static final int  _block_size           = 64;
40
    private static final int  _block_size           = 64;
40
    private static final int  _blocks_per_big_block =
41
    private static final int  _blocks_per_big_block =
41
        POIFSConstants.BIG_BLOCK_SIZE / _block_size;
42
        POIFSFileSystem.getBigBlockSize() / _block_size;
42
43
43
    private SmallDocumentBlock(final byte [] data, final int index)
44
    private SmallDocumentBlock(final byte [] data, final int index)
44
    {
45
    {
Lines 202-221 Link Here
202
        {
203
        {
203
            int buffer_offset = 0;
204
            int buffer_offset = 0;
204
205
205
            System.arraycopy(
206
            try {
206
                (( SmallDocumentBlock ) blocks[ firstBlockIndex ])._data,
207
                 System.arraycopy(
207
                firstBlockOffset, buffer, buffer_offset,
208
                        (( SmallDocumentBlock ) blocks[ firstBlockIndex ])._data,
208
                _block_size - firstBlockOffset);
209
                        firstBlockOffset, buffer, buffer_offset,
209
            buffer_offset += _block_size - firstBlockOffset;
210
                        _block_size - firstBlockOffset);
210
            for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++)
211
                    buffer_offset += _block_size - firstBlockOffset;
211
            {
212
                    for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++)
212
                System.arraycopy((( SmallDocumentBlock ) blocks[ j ])._data,
213
                    {
213
                                 0, buffer, buffer_offset, _block_size);
214
                        System.arraycopy(((SmallDocumentBlock) blocks[ j ])._data,
214
                buffer_offset += _block_size;
215
                                       0, buffer, buffer_offset, _block_size);
216
                        buffer_offset += _block_size;
217
                    }
218
                    System.arraycopy(
219
                        ((SmallDocumentBlock) blocks[ lastBlockIndex ])._data, 0,
220
                        buffer, buffer_offset, buffer.length - buffer_offset);
221
                    }
222
            catch (ArrayIndexOutOfBoundsException ignore) {
215
            }
223
            }
216
            System.arraycopy(
217
                (( SmallDocumentBlock ) blocks[ lastBlockIndex ])._data, 0,
218
                buffer, buffer_offset, buffer.length - buffer_offset);
219
        }
224
        }
220
    }
225
    }
221
226
(-)src/java/org/apache/poi/poifs/storage/HeaderBlockReader.java (-3 / +5 lines)
Lines 23-28 Link Here
23
import java.util.*;
23
import java.util.*;
24
24
25
import org.apache.poi.poifs.common.POIFSConstants;
25
import org.apache.poi.poifs.common.POIFSConstants;
26
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
26
import org.apache.poi.util.IOUtils;
27
import org.apache.poi.util.IOUtils;
27
import org.apache.poi.util.IntegerField;
28
import org.apache.poi.util.IntegerField;
28
import org.apache.poi.util.LittleEndian;
29
import org.apache.poi.util.LittleEndian;
Lines 67-76 Link Here
67
    public HeaderBlockReader(final InputStream stream)
68
    public HeaderBlockReader(final InputStream stream)
68
        throws IOException
69
        throws IOException
69
    {
70
    {
70
        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
71
        _data = new byte[ POIFSFileSystem.getBigBlockSize() ];
71
        int byte_count = IOUtils.readFully(stream, _data);
72
        int byte_count = IOUtils.readFully(stream, _data);
72
73
73
        if (byte_count != POIFSConstants.BIG_BLOCK_SIZE)
74
        if (byte_count != POIFSFileSystem.getBigBlockSize())
74
        {
75
        {
75
        	if (byte_count == -1)
76
        	if (byte_count == -1)
76
        		//Cant have -1 bytes read in the error message!
77
        		//Cant have -1 bytes read in the error message!
Lines 80-86 Link Here
80
81
81
            throw new IOException("Unable to read entire header; "
82
            throw new IOException("Unable to read entire header; "
82
                                  + byte_count + type + " read; expected "
83
                                  + byte_count + type + " read; expected "
83
                                  + POIFSConstants.BIG_BLOCK_SIZE + " bytes");
84
                                  + POIFSFileSystem.getBigBlockSize() + 
85
                                  " bytes");
84
        }
86
        }
85
87
86
        // verify signature
88
        // verify signature
(-)src/java/org/apache/poi/poifs/storage/DocumentBlock.java (-14 / +17 lines)
Lines 25-30 Link Here
25
import java.util.Arrays;
25
import java.util.Arrays;
26
26
27
import org.apache.poi.poifs.common.POIFSConstants;
27
import org.apache.poi.poifs.common.POIFSConstants;
28
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
28
import org.apache.poi.util.IOUtils;
29
import org.apache.poi.util.IOUtils;
29
import org.apache.poi.util.IntegerField;
30
import org.apache.poi.util.IntegerField;
30
import org.apache.poi.util.LittleEndian;
31
import org.apache.poi.util.LittleEndian;
Lines 82-88 Link Here
82
83
83
    private DocumentBlock()
84
    private DocumentBlock()
84
    {
85
    {
85
        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
86
        _data = new byte[ POIFSFileSystem.getBigBlockSize() ];
86
        Arrays.fill(_data, _default_value);
87
        Arrays.fill(_data, _default_value);
87
    }
88
    }
88
89
Lines 105-111 Link Here
105
106
106
    public boolean partiallyRead()
107
    public boolean partiallyRead()
107
    {
108
    {
108
        return _bytes_read != POIFSConstants.BIG_BLOCK_SIZE;
109
        return _bytes_read != POIFSFileSystem.getBigBlockSize();
109
    }
110
    }
110
111
111
    /**
112
    /**
Lines 132-138 Link Here
132
                                           final int size)
133
                                           final int size)
133
    {
134
    {
134
        DocumentBlock[] rval   =
135
        DocumentBlock[] rval   =
135
            new DocumentBlock[ (size + POIFSConstants.BIG_BLOCK_SIZE - 1) / POIFSConstants.BIG_BLOCK_SIZE ];
136
            new DocumentBlock[ (size + POIFSFileSystem.getBigBlockSize() - 1) /
137
                POIFSFileSystem.getBigBlockSize() ];
136
        int             offset = 0;
138
        int             offset = 0;
137
139
138
        for (int k = 0; k < rval.length; k++)
140
        for (int k = 0; k < rval.length; k++)
Lines 140-153 Link Here
140
            rval[ k ] = new DocumentBlock();
142
            rval[ k ] = new DocumentBlock();
141
            if (offset < array.length)
143
            if (offset < array.length)
142
            {
144
            {
143
                int length = Math.min(POIFSConstants.BIG_BLOCK_SIZE,
145
                int length = Math.min(POIFSFileSystem.getBigBlockSize(),
144
                                      array.length - offset);
146
                                      array.length - offset);
145
147
146
                System.arraycopy(array, offset, rval[ k ]._data, 0, length);
148
                System.arraycopy(array, offset, rval[ k ]._data, 0, length);
147
                if (length != POIFSConstants.BIG_BLOCK_SIZE)
149
                if (length != POIFSFileSystem.getBigBlockSize())
148
                {
150
                {
149
                    Arrays.fill(rval[ k ]._data, length,
151
                    Arrays.fill(rval[ k ]._data, length,
150
                                POIFSConstants.BIG_BLOCK_SIZE,
152
                                POIFSFileSystem.getBigBlockSize(),
151
                                _default_value);
153
                                _default_value);
152
                }
154
                }
153
            }
155
            }
Lines 155-161 Link Here
155
            {
157
            {
156
                Arrays.fill(rval[ k ]._data, _default_value);
158
                Arrays.fill(rval[ k ]._data, _default_value);
157
            }
159
            }
158
            offset += POIFSConstants.BIG_BLOCK_SIZE;
160
            offset += POIFSFileSystem.getBigBlockSize();
159
        }
161
        }
160
        return rval;
162
        return rval;
161
    }
163
    }
Lines 171-180 Link Here
171
    public static void read(final DocumentBlock [] blocks,
173
    public static void read(final DocumentBlock [] blocks,
172
                            final byte [] buffer, final int offset)
174
                            final byte [] buffer, final int offset)
173
    {
175
    {
174
        int firstBlockIndex  = offset / POIFSConstants.BIG_BLOCK_SIZE;
176
        int firstBlockIndex  = offset / POIFSFileSystem.getBigBlockSize();
175
        int firstBlockOffset = offset % POIFSConstants.BIG_BLOCK_SIZE;
177
        int firstBlockOffset = offset % POIFSFileSystem.getBigBlockSize();
176
        int lastBlockIndex   = (offset + buffer.length - 1)
178
        int lastBlockIndex   = (offset + buffer.length - 1)
177
                               / POIFSConstants.BIG_BLOCK_SIZE;
179
                               / POIFSFileSystem.getBigBlockSize();
178
180
179
        if (firstBlockIndex == lastBlockIndex)
181
        if (firstBlockIndex == lastBlockIndex)
180
        {
182
        {
Lines 187-200 Link Here
187
189
188
            System.arraycopy(blocks[ firstBlockIndex ]._data,
190
            System.arraycopy(blocks[ firstBlockIndex ]._data,
189
                             firstBlockOffset, buffer, buffer_offset,
191
                             firstBlockOffset, buffer, buffer_offset,
190
                             POIFSConstants.BIG_BLOCK_SIZE
192
                             POIFSFileSystem.getBigBlockSize()
191
                             - firstBlockOffset);
193
                             - firstBlockOffset);
192
            buffer_offset += POIFSConstants.BIG_BLOCK_SIZE - firstBlockOffset;
194
            buffer_offset += POIFSFileSystem.getBigBlockSize() - 
195
                firstBlockOffset;
193
            for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++)
196
            for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++)
194
            {
197
            {
195
                System.arraycopy(blocks[ j ]._data, 0, buffer, buffer_offset,
198
                System.arraycopy(blocks[ j ]._data, 0, buffer, buffer_offset,
196
                                 POIFSConstants.BIG_BLOCK_SIZE);
199
                                 POIFSFileSystem.getBigBlockSize());
197
                buffer_offset += POIFSConstants.BIG_BLOCK_SIZE;
200
                buffer_offset += POIFSFileSystem.getBigBlockSize();
198
            }
201
            }
199
            System.arraycopy(blocks[ lastBlockIndex ]._data, 0, buffer,
202
            System.arraycopy(blocks[ lastBlockIndex ]._data, 0, buffer,
200
                             buffer_offset, buffer.length - buffer_offset);
203
                             buffer_offset, buffer.length - buffer_offset);
(-)src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java (-2 / +7 lines)
Lines 186-193 Link Here
186
186
187
        while (currentBlock != POIFSConstants.END_OF_CHAIN)
187
        while (currentBlock != POIFSConstants.END_OF_CHAIN)
188
        {
188
        {
189
            blocks.add(blockList.remove(currentBlock));
189
            try {
190
            currentBlock = _entries.get(currentBlock);
190
              blocks.add(blockList.remove(currentBlock));
191
              currentBlock = _entries.get(currentBlock);
192
            }
193
            catch (IOException io) {
194
              currentBlock = POIFSConstants.END_OF_CHAIN;
195
            }
191
        }
196
        }
192
        return ( ListManagedBlock [] ) blocks
197
        return ( ListManagedBlock [] ) blocks
193
            .toArray(new ListManagedBlock[ 0 ]);
198
            .toArray(new ListManagedBlock[ 0 ]);
(-)src/java/org/apache/poi/poifs/storage/RawDataBlock.java (-3 / +5 lines)
Lines 19-24 Link Here
19
package org.apache.poi.poifs.storage;
19
package org.apache.poi.poifs.storage;
20
20
21
import org.apache.poi.poifs.common.POIFSConstants;
21
import org.apache.poi.poifs.common.POIFSConstants;
22
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
22
import org.apache.poi.util.IOUtils;
23
import org.apache.poi.util.IOUtils;
23
24
24
import java.io.*;
25
import java.io.*;
Lines 47-60 Link Here
47
    public RawDataBlock(final InputStream stream)
48
    public RawDataBlock(final InputStream stream)
48
        throws IOException
49
        throws IOException
49
    {
50
    {
50
        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
51
        _data = new byte[ POIFSFileSystem.getBigBlockSize() ];
51
        int count = IOUtils.readFully(stream, _data);
52
        int count = IOUtils.readFully(stream, _data);
52
53
53
        if (count == -1)
54
        if (count == -1)
54
        {
55
        {
55
            _eof = true;
56
            _eof = true;
56
        }
57
        }
57
        else if (count != POIFSConstants.BIG_BLOCK_SIZE)
58
        else if (count != POIFSFileSystem.getBigBlockSize())
58
        {
59
        {
59
        	if (count == -1)
60
        	if (count == -1)
60
        		//Cant have -1 bytes read in the error message!
61
        		//Cant have -1 bytes read in the error message!
Lines 65-71 Link Here
65
66
66
            throw new IOException("Unable to read entire block; " + count
67
            throw new IOException("Unable to read entire block; " + count
67
                                  + type + " read; expected "
68
                                  + type + " read; expected "
68
                                  + POIFSConstants.BIG_BLOCK_SIZE + " bytes");
69
                                  + POIFSFileSystem.getBigBlockSize() + 
70
                                  " bytes");
69
        }
71
        }
70
        else
72
        else
71
        {
73
        {
(-)src/java/org/apache/poi/poifs/common/POIFSConstants.java (+1 lines)
Lines 27-32 Link Here
27
public interface POIFSConstants
27
public interface POIFSConstants
28
{
28
{
29
    public static final int BIG_BLOCK_SIZE = 0x0200;
29
    public static final int BIG_BLOCK_SIZE = 0x0200;
30
    public static final int ALT_BIG_BLOCK_SIZE = 0x1000;
30
    public static final int END_OF_CHAIN   = -2;
31
    public static final int END_OF_CHAIN   = -2;
31
    public static final int PROPERTY_SIZE  = 0x0080;
32
    public static final int PROPERTY_SIZE  = 0x0080;
32
    public static final int UNUSED_BLOCK   = -1;
33
    public static final int UNUSED_BLOCK   = -1;

Return to bug 35928