This is an automated email from the ASF dual-hosted git repository.
thomasm pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 4ab4e16bc3 OAK-11977 Tree store: BufferOverflowException (#2571)
4ab4e16bc3 is described below
commit 4ab4e16bc36792b097b77042d896cc965e813ed5
Author: Thomas Mueller <[email protected]>
AuthorDate: Mon Oct 13 08:40:12 2025 +0200
OAK-11977 Tree store: BufferOverflowException (#2571)
---
.../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();
+ }
+
}