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