Skip to content

Commit acb8ef5

Browse files
thomasmuellerreschke
authored andcommitted
OAK-11977 Tree store: BufferOverflowException (#2571)
1 parent 444b02c commit acb8ef5

File tree

2 files changed

+16
-2
lines changed
  • oak-run-commons/src
    • main/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store
    • test/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store

2 files changed

+16
-2
lines changed

oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFile.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ public byte[] toBytes() {
110110
// synchronization is needed because we share the buffer
111111
synchronized (PageFile.class) {
112112
ByteBuffer buff = REUSED_BUFFER;
113-
if (buff.capacity() < sizeInBytes * 2) {
114-
buff = REUSED_BUFFER = ByteBuffer.allocate(sizeInBytes * 2);
113+
// the sizeInBytes only assumes 1 byte per character
114+
// but there can be more byte due to using UTF-8
115+
if (buff.capacity() < sizeInBytes * 4) {
116+
buff = REUSED_BUFFER = ByteBuffer.allocate(sizeInBytes * 4);
115117
}
116118
buff.rewind();
117119
// first byte may not be '4', as that is used for LZ4 compression

oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/tree/store/PageFileTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,16 @@ public void serializeInnerNode() {
6161
assertEquals(f.getUpdate(), f2.getUpdate());
6262
}
6363

64+
@Test
65+
public void largeStringTest() {
66+
PageFile f = new PageFile(false, 1_000_000);
67+
StringBuilder buff = new StringBuilder();
68+
for (int i = 0; i < 1_000_000; i++) {
69+
buff.append('\uffff');
70+
}
71+
f.appendRecord("test", buff.toString());
72+
// expected that the buffer doesn't overflow here
73+
f.toBytes();
74+
}
75+
6476
}

0 commit comments

Comments
 (0)