https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e2d0c7de30bdc6ddd7fe736ff686aabdb2a16c0a

commit e2d0c7de30bdc6ddd7fe736ff686aabdb2a16c0a
Author:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
AuthorDate: Sun Sep 22 18:04:53 2024 +0200
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Wed Sep 25 13:05:02 2024 +0200

    [FREELDR] iso.c: Perform extra validation before mounting the ISO 
filesystem (#7367)
    
    Validate the primary volume descriptor version and its reported
    logical block size.
---
 boot/freeldr/freeldr/lib/fs/iso.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/boot/freeldr/freeldr/lib/fs/iso.c 
b/boot/freeldr/freeldr/lib/fs/iso.c
index 54222b2a160..1079d578883 100644
--- a/boot/freeldr/freeldr/lib/fs/iso.c
+++ b/boot/freeldr/freeldr/lib/fs/iso.c
@@ -168,7 +168,7 @@ static ARC_STATUS IsoLookupFile(PCSTR FileName, ULONG 
DeviceId, PISO_FILE_INFO I
     RtlZeroMemory(&IsoFileInfo, sizeof(ISO_FILE_INFO));
 
     //
-    // Read The Primary Volume Descriptor
+    // Read the Primary Volume Descriptor
     //
     Position.HighPart = 0;
     Position.LowPart = 16 * SECTORSIZE;
@@ -502,9 +502,9 @@ const DEVVTBL* IsoMount(ULONG DeviceId)
 
     TRACE("Enter IsoMount(%lu)\n", DeviceId);
 
-    //
-    // Read The Primary Volume Descriptor
-    //
+    /*
+     * Read the Primary Volume Descriptor
+     */
     Position.HighPart = 0;
     Position.LowPart = 16 * SECTORSIZE;
     Status = ArcSeek(DeviceId, &Position, SeekAbsolute);
@@ -514,16 +514,24 @@ const DEVVTBL* IsoMount(ULONG DeviceId)
     if (Status != ESUCCESS || Count < sizeof(PVD))
         return NULL;
 
-    //
-    // Check if PVD is valid. If yes, return ISO9660 function table
-    //
-    if (Pvd->VdType == 1 && RtlEqualMemory(Pvd->StandardId, "CD001", 5))
+    /* Check if the PVD is valid */
+    if (!(Pvd->VdType == 1 && RtlEqualMemory(Pvd->StandardId, "CD001", 5) && 
Pvd->VdVersion == 1))
     {
-        TRACE("IsoMount(%lu) success\n", DeviceId);
-        return &Iso9660FuncTable;
+        WARN("Unrecognized CDROM format\n");
+        return NULL;
     }
+    if (Pvd->LogicalBlockSizeL != SECTORSIZE)
+    {
+        ERR("Unsupported LogicalBlockSize %u\n", Pvd->LogicalBlockSizeL);
+        return NULL;
+    }
+
+    Count = (ULONG)((ULONGLONG)Pvd->VolumeSpaceSizeL * SECTORSIZE / 1024 / 
1024);
+    TRACE("Recognized ISO9660 drive, size %lu MB (%lu sectors)\n",
+          Count, Pvd->VolumeSpaceSizeL);
 
-    return NULL;
+    /* Everything OK, return the ISO9660 function table */
+    return &Iso9660FuncTable;
 }
 
 #endif

Reply via email to