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

(-)src/java/org/apache/poi/ddf/UnknownEscherRecord.java (+12 lines)
Lines 28-33 Link Here
28
 * we do not explicitly support.
28
 * we do not explicitly support.
29
 *
29
 *
30
 * @author Glen Stampoultzis (glens at apache.org)
30
 * @author Glen Stampoultzis (glens at apache.org)
31
 * @author Zhang Zhang (zhangzzh at gmail.com)
31
 */
32
 */
32
public final class UnknownEscherRecord extends EscherRecord {
33
public final class UnknownEscherRecord extends EscherRecord {
33
    private static final byte[] NO_BYTES = new byte[0];
34
    private static final byte[] NO_BYTES = new byte[0];
Lines 42-47 Link Here
42
43
43
    public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
44
    public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
44
        int bytesRemaining = readHeader( data, offset );
45
        int bytesRemaining = readHeader( data, offset );
46
		/*
47
		 * Modified by Zhang Zhang
48
		 * Have a check between avaliable bytes and bytesRemaining, 
49
		 * take the avaliable length if the bytesRemaining out of range.
50
		 * July 09, 2010
51
		 */
52
		int avaliable = data.length - (offset + 8);
53
		if (bytesRemaining > avaliable) {
54
			bytesRemaining = avaliable;
55
		}
45
        if (isContainerRecord()) {
56
        if (isContainerRecord()) {
46
            int bytesWritten = 0;
57
            int bytesWritten = 0;
47
            thedata = new byte[0];
58
            thedata = new byte[0];
Lines 58-63 Link Here
58
            }
69
            }
59
            return bytesWritten;
70
            return bytesWritten;
60
        }
71
        }
72
61
        thedata = new byte[bytesRemaining];
73
        thedata = new byte[bytesRemaining];
62
        System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining );
74
        System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining );
63
        return bytesRemaining + 8;
75
        return bytesRemaining + 8;
(-)src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java (+38 lines)
Lines 76-82 Link Here
76
        assertTrue( r.isContainerRecord() );
76
        assertTrue( r.isContainerRecord() );
77
        assertEquals( 1, r.getChildRecords().size() );
77
        assertEquals( 1, r.getChildRecords().size() );
78
        assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() );
78
        assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() );
79
        
80
        //Add by Zhang Zhang test error situation when remaining bytes > avalible bytes
81
        testData =
82
            "00 02 " + // options
83
            "11 F1 " + // record id
84
            "05 00 00 00 " + // remaining bytes
85
            "01 02 03 04";
79
86
87
	    r = new UnknownEscherRecord();
88
	    r.fillFields( HexRead.readFromString( testData ), factory );
89
	
90
	    assertEquals( 0x0200, r.getOptions() );
91
	    assertEquals( (short) 0xF111, r.getRecordId() );
92
	    assertEquals( 12, r.getRecordSize() );
93
	    assertFalse( r.isContainerRecord() );
94
	    assertEquals( 0, r.getChildRecords().size() );
95
	    assertEquals( 4, r.getData().length );
96
	    assertEquals( 1, r.getData()[0] );
97
	    assertEquals( 2, r.getData()[1] );
98
	    assertEquals( 3, r.getData()[2] );
99
	    assertEquals( 4, r.getData()[3] );
100
	    
101
        testData =
102
            "0F 02 " + // options
103
            "11 F1 " + // record id
104
            "09 00 00 00 " + // remaining bytes
105
            "00 02 " + // options
106
            "FF FF " + // record id
107
            "00 00 00 00";      // remaining bytes
108
109
	    r = new UnknownEscherRecord();
110
	    r.fillFields( HexRead.readFromString( testData ), factory );
111
	
112
	    assertEquals( 0x020F, r.getOptions() );
113
	    assertEquals( (short) 0xF111, r.getRecordId() );
114
	    assertEquals( 8, r.getRecordSize() );
115
	    assertTrue( r.isContainerRecord() );
116
	    assertEquals( 1, r.getChildRecords().size() );
117
	    assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() );
80
    }
118
    }
81
119
82
    public void testSerialize() {
120
    public void testSerialize() {

Return to bug 49579