dulceanu commented on code in PR #3292:
URL: https://github.com/apache/jackrabbit-oak/pull/3292#discussion_r4565170858
##########
oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java:
##########
@@ -138,16 +141,39 @@ public static Index loadAndValidateIndex(RandomAccessFile
file, String name) thr
return graph;
}
+ /**
+ * The entry that follows the last segment tells whether the binary
references are present:
+ * {@code <archive>.brf} if they are, {@code <archive>.gph} or {@code
<archive>.idx} if they are
+ * missing. This tells a missing entry apart from a corrupt one, which
still has its header.
+ */
@Override
- public @NotNull ByteBuffer getBinaryReferences() throws IOException {
+ public @Nullable ByteBuffer getBinaryReferences() throws IOException {
+ int position = endOfLastSegment();
+ ByteBuffer header = access.read(position, BLOCK_SIZE);
+ String entryName = readName(header);
+ if (entryName.equals(name + ".gph") || entryName.equals(name +
".idx")) {
+ return null;
+ }
+ if (!entryName.equals(name + ".brf")) {
+ throw new IOException("Unexpected entry " + entryName + " after
the last segment of " + name);
+ }
+ int end = position + BLOCK_SIZE + readSize(header);
Review Comment:
`readSize(header)` isn't checked before it is used. The old code used
offsets taken from the already-validated index, so it didn't have this risk. A
bounds check would fix it, for example:
```int size = readSize(header);
if (size < 0 || end > access.length() - 2 * BLOCK_SIZE -
getIndexEntrySize()) {
throw new IOException("Invalid size " + size + " of binary references
entry in " + name);
}
```
This could be also checked in a test with a corrupt or large size field in
the `.brf` header.
##########
oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java:
##########
@@ -276,7 +276,7 @@ private static byte[] newEntryHeader(String name, int size)
{
// File size in bytes (octal basis)
System.arraycopy(
String.format("%011o", size).getBytes(StandardCharsets.UTF_8),
0,
- header, 124, 11);
+ header, TarEntryHeader.SIZE_OFFSET, 11);
Review Comment:
I'm wondering whether here should be `SIZE_LENGTH` instead of 11, but I see
that it has 12 as value...
##########
oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java:
##########
@@ -19,6 +19,8 @@
package org.apache.jackrabbit.oak.segment.file.tar;
import static
org.apache.jackrabbit.oak.segment.file.tar.SegmentTarWriter.getPaddingSize;
+import static
org.apache.jackrabbit.oak.segment.file.tar.TarEntryHeader.readName;
+import static
org.apache.jackrabbit.oak.segment.file.tar.TarEntryHeader.readSize;
Review Comment:
nit: static imports are placed before `TarConstants`, out of alphabetical
order.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]