Skip to content

shearwater: fix userdata corruption in predator parser samples loop - #128

Open
mikeller wants to merge 1 commit into
subsurface:Subsurface-DS9from
mikeller:fix/petrel2-analog-ppo2-userdata-corruption
Open

shearwater: fix userdata corruption in predator parser samples loop#128
mikeller wants to merge 1 commit into
subsurface:Subsurface-DS9from
mikeller:fix/petrel2-analog-ppo2-userdata-corruption

Conversation

@mikeller

@mikeller mikeller commented Sep 6, 2026

Copy link
Copy Markdown
Member

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.

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>
Copilot AI lite review requested due to automatic review settings September 6, 2026 19:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

needs_divecan_calibration_estimate breaks download from normal Petrel 2 with regular analog ppo2

2 participants