File tree Expand file tree Collapse file tree
src/main/java/org/glavo/nbt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ static ChunkRegion readRegion(RawDataReader rawReader) throws IOException {
4545 assert rawReader .position () == fileStart + 2 * ChunkUtils .SECTOR_BYTES ;
4646
4747 for (int localIndex : header .localIndexesSortedByOffset ) {
48- long sectorStart = fileStart + ( long ) header .getSectorOffset (localIndex ) * ChunkUtils . SECTOR_BYTES ;
48+ long sectorStart = fileStart + header .getSectorOffsetBytes (localIndex );
4949 long position = rawReader .position ();
5050 if (position != sectorStart ) {
5151 if (position < sectorStart ) {
@@ -62,6 +62,10 @@ static ChunkRegion readRegion(RawDataReader rawReader) throws IOException {
6262 throw new IOException ("Invalid chunk data length: " + chunkRawLength );
6363 }
6464
65+ if (chunkRawLength + 4L > header .getSectorLengthBytes (localIndex )) {
66+ throw new IOException ("Invalid chunk data length: " + chunkRawLength + " (expected <= " + header .getSectorLengthBytes (localIndex ) + " - 4)" );
67+ }
68+
6569 long chunkRawContentLength = chunkRawLength - 1L ;
6670
6771 int compressType = rawReader .readUnsignedByte ();
Original file line number Diff line number Diff line change 2525import java .util .stream .IntStream ;
2626
2727import static org .glavo .nbt .internal .ChunkUtils .CHUNKS_PRE_REGION ;
28+ import static org .glavo .nbt .internal .ChunkUtils .SECTOR_BYTES ;
2829
2930public final class ChunkRegionHeader {
3031 public static ChunkRegionHeader readHeader (DataReader reader ) throws IOException {
@@ -60,4 +61,12 @@ public int getSectorOffset(int index) {
6061 public int getSectorLength (int index ) {
6162 return ChunkUtils .getSectorLength (sectorInfo [index ]);
6263 }
64+
65+ public long getSectorOffsetBytes (int index ) {
66+ return (long ) getSectorOffset (index ) * SECTOR_BYTES ;
67+ }
68+
69+ public long getSectorLengthBytes (int index ) {
70+ return (long ) getSectorLength (index ) * SECTOR_BYTES ;
71+ }
6372}
You can’t perform that action at this time.
0 commit comments