d49eda
diff --git a/jdmarker.c b/jdmarker.c
d49eda
index 737a17c..381835b 100644
d49eda
--- a/jdmarker.c
d49eda
+++ b/jdmarker.c
d49eda
@@ -348,6 +348,12 @@ get_sos (j_decompress_ptr cinfo)
d49eda
     
d49eda
     TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
d49eda
 	     compptr->dc_tbl_no, compptr->ac_tbl_no);
d49eda
+
d49eda
+    /* This CSi (cc) should differ from the previous CSi */
d49eda
+    for (ci = 0; ci < i; ci++) {
d49eda
+      if (cinfo->cur_comp_info[ci] == compptr)
d49eda
+        ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
d49eda
+    }
d49eda
   }
d49eda
 
d49eda
   /* Collect the additional scan parameters Ss, Se, Ah/Al. */