This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1bd0fd18c5 POIFS: cap property name length to the name field when 
reading (#1551)
1bd0fd18c5 is described below

commit 1bd0fd18c51e478cf0ef4d631db6c74fc5aa442a
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Nov 9 07:30:15 2026 +0100

    POIFS: cap property name length to the name field when reading (#1551)
    
    The reading constructor only checked the lower bound of the name
    length taken from the name size field, so a large name size read past
    the 128-byte property and threw ArrayIndexOutOfBoundsException. Cap it
    at 31 characters, as setName() already does.
    
    Fixes #1545
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../org/apache/poi/poifs/property/Property.java     |  3 ++-
 .../poi/poifs/property/TestDocumentProperty.java    | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/poi/src/main/java/org/apache/poi/poifs/property/Property.java 
b/poi/src/main/java/org/apache/poi/poifs/property/Property.java
index ca34dbd76f..566f73f11d 100644
--- a/poi/src/main/java/org/apache/poi/poifs/property/Property.java
+++ b/poi/src/main/java/org/apache/poi/poifs/property/Property.java
@@ -138,7 +138,8 @@ public abstract class Property implements Child, 
POIFSViewable {
         _start_block       = new IntegerField(_start_block_offset, _raw_data);
         _size              = new IntegerField(_size_offset, _raw_data);
         _index             = index;
-        int name_length = (_name_size.get() / LittleEndianConsts.SHORT_SIZE) - 
1;
+        // The name field holds at most _max_name_length characters
+        int name_length = Math.min((_name_size.get() / 
LittleEndianConsts.SHORT_SIZE) - 1, _max_name_length);
 
         if (name_length < 1)
         {
diff --git 
a/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java 
b/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java
index c72f0bdbfa..cf87e0bca1 100644
--- a/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java
+++ b/poi/src/test/java/org/apache/poi/poifs/property/TestDocumentProperty.java
@@ -29,7 +29,9 @@ import 
org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.SummaryInformation;
 import org.apache.poi.poifs.storage.RawDataUtil;
+import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.StringUtil;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -151,4 +153,23 @@ final class TestDocumentProperty {
         byte[] output = stream.toByteArray();
         assertArrayEquals(testblock, output);
     }
+
+    /**
+     * A name size larger than the name field is capped to the field
+     *  (GitHub #1545)
+     */
+    @Test
+    void testNameSizeTooLarge() {
+        byte[] input = new byte[128];
+        // Fill the whole 64-byte name field, with no null terminator
+        for (int i = 0; i < 32; i++) {
+            LittleEndian.putShort(input, i * 2, (short) 'A');
+        }
+        LittleEndian.putShort(input, 0x40, (short) 0x7FFE);
+        // Document type
+        input[0x42] = 2;
+
+        DocumentProperty property = new DocumentProperty(0, input, 0);
+        assertEquals(StringUtil.repeat('A', 31), property.getName());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to