changeset 371:22e8ee2df9ac

Check for RSID validity, too.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 08 Oct 2021 14:04:00 +0300
parents 58c4018426da
children 911814a9d5ee
files sidinfo.c sidlib.c sidlib.h
diffstat 3 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sidinfo.c	Tue Mar 23 17:05:24 2021 +0200
+++ b/sidinfo.c	Fri Oct 08 14:04:00 2021 +0300
@@ -814,7 +814,12 @@
     switch (item->cmd)
     {
         case  0: PRS(filename, FALSE); break;
-        case  1: PRS(psid->magic, FALSE); break;
+        case  1:
+            snprintf(tmp, sizeof(tmp), "%s%s",
+                psid->magic,
+                psid->isInvalidRSID ? " (INVALID RSID!)" : "");
+            PRS(tmp, FALSE);
+            break;
         case  2:
             snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8));
             PRS(tmp, FALSE);
--- a/sidlib.c	Tue Mar 23 17:05:24 2021 +0200
+++ b/sidlib.c	Fri Oct 08 14:04:00 2021 +0300
@@ -171,7 +171,16 @@
         goto exit;
     }
 
-    psid->isRSID = psid->magic[0] == 'R';
+    if ((psid->isRSID = psid->magic[0] == 'R'))
+    {
+        if (psid->version < 2 ||
+            psid->loadAddress != 0 ||
+            psid->playAddress != 0 ||
+            psid->speed != 0)
+        {
+            psid->isInvalidRSID = TRUE;
+        }
+    }
 
     if (!sidlib_fread_str(ctx, chconv, &psid->sidName, SIDLIB_PSID_STR_LEN) ||
         !sidlib_fread_str(ctx, chconv, &psid->sidAuthor, SIDLIB_PSID_STR_LEN) ||
--- a/sidlib.h	Tue Mar 23 17:05:24 2021 +0200
+++ b/sidlib.h	Fri Oct 08 14:04:00 2021 +0300
@@ -140,7 +140,7 @@
     uint8_t  sid2Addr, sid3Addr;
 
     // Extra data
-    BOOL isRSID;
+    BOOL isRSID, isInvalidRSID;
     size_t dataSize;     // Total size of data - header
     th_md5hash_t hash;   // Songlength database hash