You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
spc_ts_to_iso8601 reformats 12-digit strings with impossible month/day into invalid ISO 8601 dates instead of returning them as-is #49
spc_ts_to_iso8601 only checks that its input is 12 ASCII digits, then reformats it as YYYY-MM-DDTHH:MM:00Z with no range validation. A 12-digit string with an impossible month or day is therefore turned into an ISO 8601 string that names no real date, e.g. 202613400000 becomes 2026-13-40T00:00:00Z. That contradicts the function's own documented contract: "YYYYMMDDHHMM" to "YYYY-MM-DDTHH:MM:00Z"; any other input is returned as is. A 12-digit string whose month is 13 is not a YYYYMMDDHHMM timestamp, so it should be returned as-is like any other non-timestamp input.
Reproduction
Feed a categorical outlook whose ISSUE / VALID / EXPIRE fields carry impossible dates:
spc::parse_categorical(body, 1) returns one feature with:
issued_at = 2026-13-40T00:00:00Z (month 13, day 40)
valid_from = 2026-02-30T00:00:00Z (February 30)
valid_until = 2026-13-01T00:00:00Z (month 13)
Verified against HEAD bfe099d with a driver linked to the built libspc_models.a / libspc_core.a. The same path is used by every model parser through as_spc_ts, so issued_at, valid_from and valid_until on categorical, probabilistic, convective, fire-weather, watch and mesoscale features are all affected.
Expected vs actual
Input
Expected
Actual
202613400000
returned as-is (202613400000)
2026-13-40T00:00:00Z
202602300000
returned as-is (202602300000)
2026-02-30T00:00:00Z
202613010000
returned as-is (202613010000)
2026-13-01T00:00:00Z
202601150000
2026-01-15T00:00:00Z
2026-01-15T00:00:00Z (correct)
Why it matters
Callers reasonably treat the *_at fields as valid ISO 8601. A downstream date parser fed 2026-13-40T00:00:00Z will fail or silently misbehave, and the failure surfaces far from the malformed feed value that caused it. SPC itself publishes well-formed timestamps, so this only bites on corrupt or hand-built payloads — but those are exactly the inputs a parser should refuse to bless as valid dates.
Root cause
src/models/json.cpp, spc_ts_to_iso8601:
if (spc_ts.size() != 12) return std::string{spc_ts};
for (constchar c : spc_ts) {
if (c < '0' || c > '9') return std::string{spc_ts};
}
// no month/day/hour/minute range check before formattingreturn std::format("{}-{}-{}T{}:{}:00Z", ...);
The digit check is the only gate. A minimal fix is to validate the ranges (month 01-12, day 01-31 with month/leap-year awareness, hour 00-23, minute 00-59) and return the input unchanged when any is out of range, matching the existing behaviour for non-12-digit and non-digit input.
flowchart TD
A["spc_ts_to_iso8601(input)"] --> B{"12 chars, all digits?"}
B -- No --> C["return input as-is"]
B -- Yes --> D["format YYYY-MM-DDTHH:MM:00Z"]
D --> E["'202613400000' -> '2026-13-40T00:00:00Z'"]
E --> F["invalid ISO 8601 reaches callers"]
F -. "fix: range-check month/day/hour/minute," -.-> C
Loading
Filed by Muse (Muse Spark 1.3). Be skeptical of the issue and replicate the issue before proceeding.
Follow-up probe (QA run 86, HEAD bfe099d): the same missing range validation also affects the hour and minute fields, not just month/day. Driving public parse_categorical with an ISSUE timestamp:
So the fix needs range checks on all five fields (month 01-12, day valid for the month, hour 00-23, minute 00-59), not just month/day. Not filing separately — same function, same root cause, same documented contract as this issue.
Filed by Muse (Muse Spark 1.3). Be skeptical of the issue and replicate the issue before proceeding.
Activity
Reddimus commentedon Nov 21, 2026
Follow-up probe (QA run 86, HEAD
bfe099d): the same missing range validation also affects the hour and minute fields, not just month/day. Driving publicparse_categoricalwith anISSUEtimestamp:issued_atreturned202601012400(hour 24)2026-01-01T24:00:00Z202601012500(hour 25)2026-01-01T25:00:00Z202601019900(hour 99)2026-01-01T99:00:00Z202601010060(minute 60)2026-01-01T00:60:00Z202601010099(minute 99)2026-01-01T00:99:00Z202601000000(day 00)2026-01-00T00:00:00Z202600010000(month 00)2026-00-01T00:00:00ZControls behave:
202601012359->2026-01-01T23:59:00Z,202601010000->2026-01-01T00:00:00Z.So the fix needs range checks on all five fields (month 01-12, day valid for the month, hour 00-23, minute 00-59), not just month/day. Not filing separately — same function, same root cause, same documented contract as this issue.
Filed by Muse (Muse Spark 1.3). Be skeptical of the issue and replicate the issue before proceeding.