Component
utils / time
Problem description
Both TimeUtils.isValidTimestampFormat overloads use SimpleDateFormat.parse(String) with the default lenient mode and without checking that the entire input was consumed.
Relevant code:
https://github.com/ZSvirt/zsvirt/blob/main/utils/src/main/java/org/zstack/utils/TimeUtils.java#L144-L161
As a result, values such as 2024-02-30 10:00:00 and values with trailing characters can be accepted as valid.
Steps to reproduce
- Call
TimeUtils.isValidTimestampFormat("2024-02-30 10:00:00").
- Call
TimeUtils.isValidTimestampFormat("2024-01-01 10:00:00xyz").
- Observe that the method returns
true.
Expected behavior
Validation should reject calendar-invalid dates and any unparsed trailing input.
Proposed fix
Set setLenient(false) and use a ParsePosition or equivalent full-input check for both overloads. Add regression tests for leap-day boundaries, invalid dates, and trailing characters.
Component
utils / time
Problem description
Both
TimeUtils.isValidTimestampFormatoverloads useSimpleDateFormat.parse(String)with the default lenient mode and without checking that the entire input was consumed.Relevant code:
https://github.com/ZSvirt/zsvirt/blob/main/utils/src/main/java/org/zstack/utils/TimeUtils.java#L144-L161
As a result, values such as
2024-02-30 10:00:00and values with trailing characters can be accepted as valid.Steps to reproduce
TimeUtils.isValidTimestampFormat("2024-02-30 10:00:00").TimeUtils.isValidTimestampFormat("2024-01-01 10:00:00xyz").true.Expected behavior
Validation should reject calendar-invalid dates and any unparsed trailing input.
Proposed fix
Set
setLenient(false)and use aParsePositionor equivalent full-input check for both overloads. Add regression tests for leap-day boundaries, invalid dates, and trailing characters.