Skip to content

Commit a0e3ab5

Browse files
committed
WarcReader: use a little-endian view of the buffer for magic probing
1 parent 48fffcb commit a0e3ab5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/org/netpreserve/jwarc/WarcReader.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ public WarcReader(ReadableByteChannel channel, ByteBuffer buffer) throws IOExcep
7979
}
8080
}
8181

82-
buffer.order(ByteOrder.LITTLE_ENDIAN);
83-
if (buffer.getShort(buffer.position()) == GzipChannel.GZIP_MAGIC) {
82+
ByteBuffer leBuffer = buffer.asReadOnlyBuffer();
83+
leBuffer.order(ByteOrder.LITTLE_ENDIAN);
84+
if (leBuffer.getShort(buffer.position()) == (short) 0x8b1f) {
8485
this.channel = new GunzipChannel(channel, buffer);
8586
this.buffer = ByteBuffer.allocate(8192);
8687
this.buffer.flip();
8788
compression = WarcCompression.GZIP;
88-
} else if (buffer.getInt(buffer.position()) == 0xfd2fb528 || buffer.getInt(buffer.position()) == 0x184D2A5D) {
89+
} else if (leBuffer.getInt(buffer.position()) == 0xfd2fb528 ||
90+
leBuffer.getInt(buffer.position()) == 0x184D2A5D) {
8991
try {
9092
this.channel = (ReadableByteChannel) Class.forName("org.netpreserve.jwarc.ZstdDecompressingChannel")
9193
.getConstructor(ReadableByteChannel.class, ByteBuffer.class)

0 commit comments

Comments
 (0)