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 <[email protected]> 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(); + } + }
