shearwater: fix userdata corruption in predator parser samples loop - #128
Open
mikeller wants to merge 1 commit into
Open
shearwater: fix userdata corruption in predator parser samples loop#128mikeller wants to merge 1 commit into
mikeller wants to merge 1 commit into
Conversation
shearwater_predator_parser_samples_foreach serves two purposes: an internal calibration pre-pass called with callback=NULL and a dc_parser_sensor_calibration_t * as userdata, and normal sample enumeration called with a real callback and the caller's own userdata. The guard that restricted calibration writes to the pre-pass checked only that userdata was non-NULL, so during normal sample enumeration it cast the caller's userdata pointer to dc_parser_sensor_calibration_t * and wrote into it. For any CCR dive with internal (non-external) ppo2, this wrote the value 1 into the first byte of whatever struct the caller passed, e.g. the low byte of divecomputer::when in Subsurface (a small timestamp corruption) or a FILE * member in dctool (a crash). Fix: add !callback to the guard so the internal calibration writes only happen during the pre-pass (callback == NULL). Signed-off-by: Michael Keller <github@ike.ch>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change correctly limits calibration writes to the documented pre-pass path (callback == NULL) and the calibration pre-pass call site is present and consistent with this contract.
Pull request overview
Fixes a bug in the Shearwater Predator samples loop where the function’s dual-use of userdata (calibration pre-pass vs. normal enumeration) could corrupt caller-provided userdata during normal sample callbacks.
Changes:
- Restrict internal calibration writes to only occur during the calibration pre-pass by additionally requiring
callback == NULL.
File summaries
| File | Description |
|---|---|
| src/shearwater_predator_parser.c | Gates calibration-struct writes on !callback to prevent writing into caller userdata during normal sample enumeration. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
shearwater_predator_parser_samples_foreach serves two purposes:
an internal calibration pre-pass called with callback=NULL and a
dc_parser_sensor_calibration_t * as userdata, and normal sample
enumeration called with a real callback and the caller's own userdata.
The guard that restricted calibration writes to the pre-pass checked
only that userdata was non-NULL, so during normal sample enumeration it
cast the caller's userdata pointer to dc_parser_sensor_calibration_t *
and wrote into it. For any CCR dive with internal (non-external) ppo2,
this wrote the value 1 into the first byte of whatever struct the caller
passed, e.g. the low byte of divecomputer::when in Subsurface (a small
timestamp corruption) or a FILE * member in dctool (a crash).
Fix: add !callback to the guard so the internal calibration writes only
happen during the pre-pass (callback == NULL).
Fixes #127.