Skip to content

Commit 80fa276

Browse files
Avoid fatal errors when v2 record blockettes contain invalid time stamps
1 parent 103a11a commit 80fa276

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
2025.233:
22
- Add ms_nstime2timestr_n() with string size limit, deprecate ms_nstime2timestr().
33
- With ms_nstime2timestr_n() print "ERROR" for NSTERROR and "UNSET" for NSTUNSET.
4+
- Avoid fatal errors when v2 record blockettes contain invalid time stamps.
45

56
2025.227:
67
- Properly round negative values when converting floats to integers

extraheaders.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ mseh_add_event_detection_r (MS3Record *msr, const char *ptr,
556556
yyjson_mut_set_str (&units, eventdetection->units);
557557
yyjson_mut_obj_add (&entry, &units_key, &units);
558558
}
559-
if (eventdetection->onsettime != NSTERROR && eventdetection->onsettime != NSTUNSET)
559+
if (eventdetection->onsettime != NSTUNSET)
560560
{
561561
if (ms_nstime2timestr_n (eventdetection->onsettime, timestring, sizeof(timestring), ISOMONTHDAY_Z, NANO_MICRO_NONE))
562562
{
@@ -669,7 +669,7 @@ mseh_add_calibration_r (MS3Record *msr, const char *ptr,
669669
yyjson_mut_set_str (&type, calibration->type);
670670
yyjson_mut_obj_add (&entry, &type_key, &type);
671671
}
672-
if (calibration->begintime != NSTERROR && calibration->begintime != NSTUNSET)
672+
if (calibration->begintime != NSTUNSET)
673673
{
674674
if (ms_nstime2timestr_n (calibration->begintime, beginstring, sizeof(beginstring), ISOMONTHDAY_Z, NANO_MICRO_NONE))
675675
{
@@ -683,7 +683,7 @@ mseh_add_calibration_r (MS3Record *msr, const char *ptr,
683683
return MS_GENERROR;
684684
}
685685
}
686-
if (calibration->endtime != NSTERROR && calibration->endtime != NSTUNSET)
686+
if (calibration->endtime != NSTUNSET)
687687
{
688688
if (ms_nstime2timestr_n (calibration->endtime, endstring, sizeof(endstring), ISOMONTHDAY_Z, NANO_MICRO_NONE))
689689
{
@@ -841,7 +841,7 @@ mseh_add_timing_exception_r (MS3Record *msr, const char *ptr,
841841
yyjson_mut_set_obj (&entry);
842842

843843
/* Add elements to new object */
844-
if (exception->time != NSTERROR && exception->time != NSTUNSET)
844+
if (exception->time != NSTUNSET)
845845
{
846846
if (ms_nstime2timestr_n (exception->time, timestring, sizeof(timestring), ISOMONTHDAY_Z, NANO_MICRO_NONE))
847847
{
@@ -936,7 +936,7 @@ mseh_add_recenter_r (MS3Record *msr, const char *ptr, MSEHRecenter *recenter,
936936
yyjson_mut_set_str (&type, recenter->type);
937937
yyjson_mut_obj_add (&entry, &type_key, &type);
938938
}
939-
if (recenter->begintime != NSTERROR && recenter->begintime != NSTUNSET)
939+
if (recenter->begintime != NSTUNSET)
940940
{
941941
if (ms_nstime2timestr_n (recenter->begintime, beginstring, sizeof(beginstring), ISOMONTHDAY_Z, NANO_MICRO_NONE))
942942
{
@@ -950,7 +950,7 @@ mseh_add_recenter_r (MS3Record *msr, const char *ptr, MSEHRecenter *recenter,
950950
return MS_GENERROR;
951951
}
952952
}
953-
if (recenter->endtime != NSTERROR && recenter->endtime != NSTUNSET)
953+
if (recenter->endtime != NSTUNSET)
954954
{
955955
if (ms_nstime2timestr_n (recenter->endtime, endstring, sizeof(endstring), ISOMONTHDAY_Z, NANO_MICRO_NONE))
956956
{

unpack.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,6 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
491491
strncpy (eventdetection.units, "COUNTS", sizeof (eventdetection.units));
492492

493493
eventdetection.onsettime = ms_btime2nstime ((uint8_t*)pMS2B200_YEAR (record + blkt_offset), msr->swapflag);
494-
if (eventdetection.onsettime == NSTERROR)
495-
return MS_GENERROR;
496494

497495
memset (eventdetection.medsnr, 0, 6);
498496
eventdetection.medlookback = -1;
@@ -524,8 +522,6 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
524522
strncpy (eventdetection.wave, "COMPRESSION", sizeof (eventdetection.wave));
525523

526524
eventdetection.onsettime = ms_btime2nstime ((uint8_t*)pMS2B201_YEAR (record + blkt_offset), msr->swapflag);
527-
if (eventdetection.onsettime == NSTERROR)
528-
return MS_GENERROR;
529525

530526
memcpy (eventdetection.medsnr, pMS2B201_MEDSNR (record + blkt_offset), 6);
531527
eventdetection.medlookback = *pMS2B201_LOOPBACK (record + blkt_offset);
@@ -547,10 +543,8 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
547543
strncpy (calibration.type, "STEP", sizeof (calibration.type));
548544

549545
calibration.begintime = ms_btime2nstime ((uint8_t*)pMS2B300_YEAR (record + blkt_offset), msr->swapflag);
550-
if (calibration.begintime == NSTERROR)
551-
return MS_GENERROR;
552546

553-
calibration.endtime = NSTERROR;
547+
calibration.endtime = NSTUNSET;
554548
calibration.steps = *pMS2B300_NUMCALIBRATIONS (record + blkt_offset);
555549

556550
/* If bit 0 is set, first puluse is positive */
@@ -602,10 +596,8 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
602596
strncpy (calibration.type, "SINE", sizeof (calibration.type));
603597

604598
calibration.begintime = ms_btime2nstime ((uint8_t*)pMS2B310_YEAR (record + blkt_offset), msr->swapflag);
605-
if (calibration.begintime == NSTERROR)
606-
return MS_GENERROR;
607599

608-
calibration.endtime = NSTERROR;
600+
calibration.endtime = NSTUNSET;
609601
calibration.steps = -1;
610602
calibration.firstpulsepositive = -1;
611603
calibration.alternatesign = -1;
@@ -659,10 +651,8 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
659651
strncpy (calibration.type, "PSEUDORANDOM", sizeof (calibration.type));
660652

661653
calibration.begintime = ms_btime2nstime ((uint8_t*)pMS2B320_YEAR (record + blkt_offset), msr->swapflag);
662-
if (calibration.begintime == NSTERROR)
663-
return MS_GENERROR;
664654

665-
calibration.endtime = NSTERROR;
655+
calibration.endtime = NSTUNSET;
666656
calibration.steps = -1;
667657
calibration.firstpulsepositive = -1;
668658
calibration.alternatesign = -1;
@@ -710,10 +700,8 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
710700
strncpy (calibration.type, "GENERIC", sizeof (calibration.type));
711701

712702
calibration.begintime = ms_btime2nstime ((uint8_t*)pMS2B390_YEAR (record + blkt_offset), msr->swapflag);
713-
if (calibration.begintime == NSTERROR)
714-
return MS_GENERROR;
715703

716-
calibration.endtime = NSTERROR;
704+
calibration.endtime = NSTUNSET;
717705
calibration.steps = -1;
718706
calibration.firstpulsepositive = -1;
719707
calibration.alternatesign = -1;
@@ -756,11 +744,9 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
756744

757745
strncpy (calibration.type, "ABORT", sizeof (calibration.type));
758746

759-
calibration.begintime = NSTERROR;
747+
calibration.begintime = NSTUNSET;
760748

761749
calibration.endtime = ms_btime2nstime ((uint8_t*)pMS2B395_YEAR (record + blkt_offset), msr->swapflag);
762-
if (calibration.endtime == NSTERROR)
763-
return MS_GENERROR;
764750

765751
calibration.steps = -1;
766752
calibration.firstpulsepositive = -1;
@@ -807,8 +793,6 @@ msr3_unpack_mseed2 (const char *record, int reclen, MS3Record **ppmsr,
807793
exception.vcocorrection = HO4f (*pMS2B500_VCOCORRECTION (record + blkt_offset), msr->swapflag);
808794

809795
exception.time = ms_btime2nstime ((uint8_t*)pMS2B500_YEAR (record + blkt_offset), msr->swapflag);
810-
if (exception.time == NSTERROR)
811-
return MS_GENERROR;
812796

813797
/* Apply microsecond precision if non-zero */
814798
if (*pMS2B500_MICROSECOND (record + blkt_offset) != 0)

0 commit comments

Comments
 (0)