@@ -313,23 +313,17 @@ private static Block readDirectBlock(SeekableByteChannel channel, FractalHeapHea
313313 if (dataSize < 0 ) {
314314 throw new IOException ("Invalid data size in direct block" );
315315 }
316- // Determine the maximum number of bytes that can be read
317- long fSize = channel .size ();
318- long fPosition = channel .position ();
319- long bytesRemainingInFile = fSize - fPosition ;
320-
321- // The actual size to read is the smaller of the two values
322- long actualReadSize = Math .min (dataSize , bytesRemainingInFile );
323- headerBuffer = ByteBuffer .allocate ((int ) actualReadSize ).order (ByteOrder .LITTLE_ENDIAN );
316+ blockSize = dataSize - headerSize ;
317+ headerBuffer = ByteBuffer .allocate ((int ) blockSize ).order (ByteOrder .LITTLE_ENDIAN );
324318 bytesRead = channel .read (headerBuffer );
325- if ( bytesRead != actualReadSize )
319+ if ( bytesRead != blockSize )
326320 throw new IllegalStateException ();
327321 headerBuffer .flip ();
328322
329323 byte [] data = headerBuffer .array ();
330324 DirectBlock db = new DirectBlock ();
331325 db .blockOffset = blockOffset .getInstance (Long .class );
332- db .blockSize = actualReadSize ;
326+ db .blockSize = dataSize ;
333327 db .data = data ;
334328 db .filterMask = filterMask ;
335329 db .checksum = checksum ;
@@ -399,7 +393,12 @@ private static List<ChildInfo> parseChildInfos(ByteBuffer blockBuffer, FractalHe
399393 long startingBlockSize = header .startingBlockSize .getInstance (Long .class );
400394
401395 for (short r = 0 ; r < nrows ; r ++) {
402- long rowBlockSize = startingBlockSize * (1L << r );
396+ // --- Corrected Logic ---
397+ // Calculate the exponent: 0 for rows 0 and 1, then 1, 2, 3...
398+ long exponent = Math .max (0L , r - 1 );
399+ long rowBlockSize = startingBlockSize * (1L << exponent );
400+ // --- End Corrected Logic ---
401+
403402 for (int c = 0 ; c < header .tableWidth ; c ++) {
404403 HdfFixedPoint childAddress = HdfReadUtils .readHdfFixedPointFromBuffer (sizeOfOffset , blockBuffer );
405404 HdfFixedPoint childFilteredSize = sizeOfOffset .undefined ();
@@ -482,7 +481,8 @@ private static long getBlockSize(FractalHeapHeader header, long blockOffset) thr
482481 }
483482 double arg = ((double ) blockOffset / (header .tableWidth * header .startingBlockSize .getInstance (Long .class ))) + 1 ;
484483 int row = (int ) Math .floor (Math .log (arg ) / Math .log (2 ));
485- return startingBlockSize * (1L << row );
484+ long exponent = Math .max (0L , row - 1 );
485+ return startingBlockSize * (1L << exponent );
486486 }
487487
488488 public byte [] getObject (ParsedHeapId heapId ) {
0 commit comments