fix(sysdig): prevent integer underflow when an event with timestamp prior to duration_start is logged while using '-M' CLI flag#2182
Merged
therealbobo merged 1 commit intodraios:devfrom Apr 1, 2026
Conversation
… timestamp prior to duration_start is logged while using '-M' CLI flag Signed-off-by: Chris Yang <chris.yang@shopify.com>
therealbobo
approved these changes
Apr 1, 2026
Contributor
therealbobo
left a comment
There was a problem hiding this comment.
good catch! thanks! lgtm!
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.
tl;dr
Currently, when using the
-MCLI flag to set amax_secondsfor which the capture will run, there exists an edge case where a kernel event will come in with a timestamp earlier than the recorded start time, which will cause the program to exit immediately.details
Since the
fstatfsevent has a timestamp smaller than thecontainer_pluginevents and thatev->get_ts()on thelibsinspevent returns auint64_t,ev->get_ts() - duration_starton event 3 causes an integer underflow and wraps around to UINT64_MAX, which will always be bigger than the total duration specified by the-MCLI flag if it was used and would cause the program to exit prematurely despite not having hit the set time limit, no matter how long the time limit actually is. This should only really a problem at the very beginning of the processThis PR adds a check to ensure that the current timestamp is greater than the initial recorded timestamp and to keep going if it isn't. This should ensure that any events that are timestamped slightly before the
duration_startare captured as well and does not cause the CLI tool to exit.testing
sudo sysdig -v -M 10 -w /tmp/test.scapsudo sysdig -v -M 10 -w /tmp/test.scap