fix(util): avoid panic when parsing a bare "s" duration - #2633
Open
BOURBONCASK wants to merge 2 commits into
Open
fix(util): avoid panic when parsing a bare "s" duration#2633BOURBONCASK wants to merge 2 commits into
BOURBONCASK wants to merge 2 commits into
Conversation
`parse_duration` reads the duration's trailing byte to detect its unit. For the `s` unit it then reads a *second* byte to disambiguate `s` (seconds) from `ms` (milliseconds), using `it.next().unwrap()`. The leading `is_empty()` guard only covers the first `next()`, so the input `"s"` (a unit with no numeric part) exhausts the iterator and the second `unwrap()` panics with `called Option::unwrap() on a None value`. Every other unit-only input (`"u"`, `"m"`, `"h"`, ...) already returns an error; `"s"` is the only one that double-consumes. This is reachable from the public time DSL via `TimeExpr`/`TimeRange` parsing, e.g. a selector parameter `_time=[now(s)..]`, so untrusted input can trigger the panic. Handle the exhausted-iterator case like the other unit-only inputs and return a parse error instead of panicking. Extend `test_parse_duration` with unit-only inputs and end-to-end `TimeExpr`/`TimeRange` cases. Signed-off-by: yifei.ma <yifeima98@gmail.com>
oteffahi
suggested changes
Jun 16, 2026
oteffahi
left a comment
Contributor
There was a problem hiding this comment.
Small nitpick. Otherwise LGTM.
Co-authored-by: Oussama Teffahi <70609372+oteffahi@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What does this PR do?
parse_duration(inzenoh-util's time DSL) panics on the input"s".It reads the duration's trailing byte to detect the unit, and for
sit reads a second byte to disambiguates(seconds) fromms(milliseconds):The leading
is_empty()guard only covers the firstnext(). The input"s"(a unit with no numeric part) exhausts the iterator, so the secondunwrap()panics withcalled Option::unwrap() on a None value. Every other unit-only input ("u","m","h","d","w") only callsnext()once and already returns anErr;"s"is the only unit that double-consumes.This change handles the exhausted-iterator case like the other unit-only inputs and returns a parse error instead of panicking. It also extends
test_parse_durationwith all unit-only inputs and end-to-endTimeExpr/TimeRangecases.Minimal repro on
main:Why is this change needed?
parse_durationis reachable from the public time DSL (TimeExpr/TimeRange), which backs the standardized_timeselector parameter (ZenohParameters::time_range()). That value comes from the querier's selector, so a malformed_time(e.g._time=[now(s)..]) is untrusted input that can panic the parsing side — both when sending aget()(ConsolidationMode::Autoreadstime_range()) and on a queryable/storage that inspects_time.The intent is clearly to fail gracefully:
time_range()returnsOption<ZResult<TimeRange>>, i.e. malformed input is supposed to yield anErr, not a panic. This follows the same "reject malformed input instead of panicking" direction as recent parsing fixes.Related Issues
N/A — found via review of the time-DSL parsing path.
🏷️ Label-Based Checklist
Based on the labels applied to this PR, please complete these additional requirements:
Labels:
bug🐛 Bug Fix Requirements
Since this PR is labeled as a bug fix, please ensure:
Why this matters: Bugs without tests often reoccur.
Instructions:
- [ ]to- [x])This checklist updates automatically when labels change, but preserves your checked boxes.