--- src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java (revision 3139) +++ src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java (working copy) @@ -43,6 +43,8 @@ public String field_5_ole_classname; // Classname of the embedded OLE document (e.g. Word.Document.8) public int field_6_stream_id; // ID of the OLE stream containing the actual data. + private int field_5_ole_classname_padding; // developer laziness... + public EmbeddedObjectRefSubRecord() { } @@ -93,9 +95,11 @@ // Padded with NUL bytes. The -2 is because field_1_stream_id_offset // is relative to after the offset field, whereas in.getRecordOffset() - // is relative to the start of this record. + // is relative to the start of this record (minus the header.) + field_5_ole_classname_padding = 0; while (in.getRecordOffset() - 2 < field_1_stream_id_offset) { + field_5_ole_classname_padding++; in.readByte(); // discard } @@ -106,6 +110,9 @@ { int pos = offset; + LittleEndian.putShort(data, pos, sid); pos += 2; + LittleEndian.putShort(data, pos, (short)(getRecordSize() - 4)); pos += 2; + LittleEndian.putShort(data, pos, field_1_stream_id_offset); pos += 2; LittleEndian.putShortArray(data, pos, field_2_unknown); pos += field_2_unknown.length * 2 + 2; LittleEndian.putShort(data, pos, field_3_unicode_len); pos += 2; @@ -120,9 +127,10 @@ StringUtil.putCompressedUnicode( field_5_ole_classname, data, pos ); pos += field_5_ole_classname.length(); } - // Padded with NUL bytes. - pos = field_1_stream_id_offset; - + // Padded with the same number of NUL bytes as were originally skipped. + // XXX: This is only accurate until we make the classname mutable. + pos += field_5_ole_classname_padding; + LittleEndian.putInt(data, pos, field_6_stream_id); pos += 4; return getRecordSize(); @@ -133,8 +141,9 @@ */ public int getRecordSize() { - // Conveniently this stores the length of all the crap before the final int value. - return field_1_stream_id_offset + 4; + // The stream id offset is relative to after the stream ID. + // Add 2 bytes for the stream id offset and 4 bytes for the stream id itself. + return field_1_stream_id_offset + 2 + 4; } /**