You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2025/10/10 10:01:07 UTC

(jackrabbit-oak) branch OAK-11977 created (now 174f0b186e)

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

thomasm pushed a change to branch OAK-11977
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


      at 174f0b186e OAK-11977 Tree store: BufferOverflowException

This branch includes the following new commits:

     new 174f0b186e OAK-11977 Tree store: BufferOverflowException

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(jackrabbit-oak) 01/01: OAK-11977 Tree store: BufferOverflowException

Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

thomasm pushed a commit to branch OAK-11977
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 174f0b186e376b0a117fd26aaed235663d0b7f02
Author: Thomas Mueller <mu...@adobe.com>
AuthorDate: Fri Oct 10 11:58:37 2025 +0200

    OAK-11977 Tree store: BufferOverflowException
---
 .../oak/index/indexer/document/tree/store/PageFile.java      |  6 ++++--
 .../oak/index/indexer/document/tree/store/PageFileTest.java  | 12 ++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFile.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFile.java
index 8cc5f01b22..4439fd22fe 100644
--- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFile.java
+++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFile.java
@@ -110,8 +110,10 @@ public class PageFile implements MemoryObject {
         // synchronization is needed because we share the buffer
         synchronized (PageFile.class) {
             ByteBuffer buff = REUSED_BUFFER;
-            if (buff.capacity() < sizeInBytes * 2) {
-                buff = REUSED_BUFFER = ByteBuffer.allocate(sizeInBytes * 2);
+            // the sizeInBytes only assumes 1 byte per character
+            // but there can be more byte due to using UTF-8
+            if (buff.capacity() < sizeInBytes * 4) {
+                buff = REUSED_BUFFER = ByteBuffer.allocate(sizeInBytes * 4);
             }
             buff.rewind();
             // first byte may not be '4', as that is used for LZ4 compression
diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFileTest.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFileTest.java
index 57122da06f..00f2a20072 100644
--- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFileTest.java
+++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFileTest.java
@@ -61,4 +61,16 @@ public class PageFileTest {
         assertEquals(f.getUpdate(), f2.getUpdate());
     }
 
+    @Test
+    public void largeStringTest() {
+        PageFile f = new PageFile(false, 1_000_000);
+        StringBuilder buff = new StringBuilder();
+        for (int i = 0; i < 1_000_000; i++) {
+            buff.append('\uffff');
+        }
+        f.appendRecord("test", buff.toString());
+        // expected that the buffer doesn't overflow here
+        f.toBytes();
+    }
+
 }