소스 검색

Add explicit bounds checking for read CD commands.

saybur 2 년 전
부모
커밋
fe747e2ac0
1개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      src/BlueSCSI_cdrom.cpp

+ 13 - 0
src/BlueSCSI_cdrom.cpp

@@ -1114,6 +1114,19 @@ static void doReadCD(uint32_t lba, uint32_t length, uint8_t sector_type,
            ", main channel ", main_channel, ", sub channel ", sub_channel,
            ", data offset in file ", (int)offset);
 
+    // Ensure read is not out of range of the image
+    uint64_t readend = offset + trackinfo.sector_length * length;
+    if (readend > img.file.size())
+    {
+        logmsg("WARNING: Host attempted CD read at sector ", lba, "+", length,
+              ", exceeding image size ", img.file.size());
+        scsiDev.status = CHECK_CONDITION;
+        scsiDev.target->sense.code = ILLEGAL_REQUEST;
+        scsiDev.target->sense.asc = LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
+        scsiDev.phase = STATUS;
+        return;
+    }
+
     // Verify sector type
     if (sector_type != 0)
     {