@@ -545,3 +545,40 @@ func TestGetDataPreparerID(t *testing.T) {
545545 // Data preparer ID is at a different offset - our minimal ISO doesn't set it
546546 _ = iso .GetDataPreparerID ()
547547}
548+
549+ // TestISO9660_TruncatedPathTable verifies bounds check for malformed path table entries.
550+ func TestISO9660_TruncatedPathTable (t * testing.T ) {
551+ t .Parallel ()
552+
553+ tmpDir := t .TempDir ()
554+
555+ // Create a minimal ISO
556+ isoData := createMinimalISO ("VOL" , "SYS" , "PUB" )
557+
558+ // Corrupt the path table: set a directory name length that exceeds the path table size
559+ // Path table is at block 18 (offset 18 * 2048 = 36864)
560+ pathTableOffset := 18 * 2048
561+
562+ // Set directory name length to a large value (e.g., 100) that exceeds remaining data
563+ // The path table entry format is:
564+ // - byte 0: directory name length
565+ // - byte 1: extended attribute record length
566+ // - bytes 2-5: directory LBA (little-endian)
567+ // - bytes 6-7: parent directory number (little-endian)
568+ // - bytes 8+: directory name
569+ isoData [pathTableOffset ] = 100 // Large name length that would overflow
570+
571+ isoPath := filepath .Join (tmpDir , "truncated.iso" )
572+ if err := os .WriteFile (isoPath , isoData , 0o600 ); err != nil {
573+ t .Fatalf ("Failed to write ISO: %v" , err )
574+ }
575+
576+ // This should fail with a truncated path table error, not panic
577+ _ , err := Open (isoPath )
578+ if err == nil {
579+ t .Error ("Open() should error for truncated path table entry" )
580+ }
581+ if ! strings .Contains (err .Error (), "truncated path table entry" ) {
582+ t .Errorf ("Open() error = %v, want error containing 'truncated path table entry'" , err )
583+ }
584+ }
0 commit comments