]> sigrok.org Git - libsigrokdecode.git/commitdiff
Return SRD_ERR_ARG from srd_inst_decode if samplenums are wrong
authorMarcus Comstedt <redacted>
Sun, 26 Feb 2017 12:07:03 +0000 (13:07 +0100)
committerUwe Hermann <redacted>
Sun, 26 Feb 2017 13:56:56 +0000 (14:56 +0100)
This validates the requirements that
* abs_start_samplenum continues where the previous decode ended
* abs_end_samplenum is not lower than abs_start_samplenum

Failure to meet these requirements will make v3 decoders crash.

instance.c

index a1de9574520d7511211520938c81d73b33dc0df3..0e27ca31e1190edb2e8269ce9a08f53d4f948b21 100644 (file)
@@ -1010,6 +1010,12 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di,
                return SRD_ERR_ARG;
        }
 
+       if (abs_start_samplenum != di->abs_cur_samplenum ||
+           abs_end_samplenum < abs_start_samplenum) {
+               srd_dbg("incorrect sample numbers");
+               return SRD_ERR_ARG;
+       }
+
        di->data_unitsize = unitsize;
 
        srd_dbg("Decoding: abs start sample %" PRIu64 ", abs end sample %"
@@ -1042,6 +1048,7 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di,
                                        di->inst_id);
                        return SRD_ERR_PYTHON;
                }
+               di->abs_cur_samplenum = abs_end_samplenum;
                Py_DecRef(py_res);
        } else {
                /* If this is the first call, start the worker thread. */