Author: tilman
Date: Wed Oct 15 09:39:58 2025
New Revision: 1929152

Log:
PDFBOX-6083: catch length 0 case + plus test

Modified:
   pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
   
pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java

Modified: 
pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
==============================================================================
--- pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java    
Wed Oct 15 09:28:06 2025        (r1929151)
+++ pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java    
Wed Oct 15 09:39:58 2025        (r1929152)
@@ -189,7 +189,7 @@ public interface RandomAccessRead extend
             throw new EOFException("Premature end of buffer reached");
         }
         int bytesReadTotal = 0;
-        do
+        while (bytesReadTotal < length)
         {
             int bytesReadNow = read(b, offset + bytesReadTotal, length - 
bytesReadTotal);
             if (bytesReadNow <= 0)
@@ -198,6 +198,5 @@ public interface RandomAccessRead extend
             }
             bytesReadTotal += bytesReadNow;
         }
-        while (bytesReadTotal < length);
     }
 }

Modified: 
pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java
==============================================================================
--- 
pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java
    Wed Oct 15 09:28:06 2025        (r1929151)
+++ 
pdfbox/trunk/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java
    Wed Oct 15 09:39:58 2025        (r1929152)
@@ -296,4 +296,17 @@ class RandomAccessReadBufferedFileTest
             Assertions.assertArrayEquals(expectedBytes, b);
         }
     }
+
+    @Test
+    void testReadFullyNothing() throws IOException, URISyntaxException
+    {
+        try (RandomAccessRead randomAccessSource = new 
RandomAccessReadBufferedFile(
+                new 
File(getClass().getResource("RandomAccessReadFile1.txt").toURI())))
+        {
+            assertEquals(0, randomAccessSource.getPosition());
+            byte[] b = new byte[0];
+            randomAccessSource.readFully(b);
+            assertEquals(0, randomAccessSource.getPosition());
+        }
+    }
 }

Reply via email to