diff --git a/src/crf/src/crf1d_model.c b/src/crf/src/crf1d_model.c index 426fd9e..fb7e8e7 100644 --- a/src/crf/src/crf1d_model.c +++ b/src/crf/src/crf1d_model.c @@ -496,6 +496,11 @@ int crf1dmw_put_labelref(crf1dmw_t* writer, int lid, const feature_refs_t* ref, return CRFSUITEERR_INTERNAL_LOGIC; } + /* Validate lid is within bounds */ + if (lid < 0 || (uint32_t)lid >= href->num) { + return CRFSUITEERR_INTERNAL_LOGIC; + } + /* Store the current offset to the offset array. */ href->offsets[lid] = ftell(fp);