Repository navigation
fix: check WIRE record size against the active definition - #91
Merged
Merged
Conversation
Component expansion and compressed-timestamp reconstruction add fields to a decoded message that its definition never writes: enhanced_speed derived from speed, enhanced_altitude from altitude, and field 253 rebuilt from the 5-bit offset. DataMessage.size counted them, so WIRE compared a projected size with a wire size. 9,143 of the 9,194 data records in Garmin's Activity.fit were reported oversized, and to_bytes(strict=True) / FitFileBuilder(strict=True) refused files that round-trip byte-for-byte. validate_data_message now sums the payload from the active definition, counting a listed field at its own size or, when it was cleared in memory, at its definition size because encode pads it with protocol-invalid bytes. A genuine size mismatch is still reported. An Activity file_id no longer requires serial_number: Garmin's FIT documentation marks the field optional and Garmin's own activity files (Edge 1030 Plus, Forerunner 945 and Fenix 3 samples) omit it, carrying the device serial in device_info instead. Tests: a standard Garmin activity validates with no findings and re-encodes byte-identically under strict mode; component-expanded and compressed-timestamp records are not counted as payload; a corrupted definition size is still caught. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f763-9923-75c7-b1ef-d1817be4902d
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #91 +/- ##
==========================================
+ Coverage 93.21% 93.35% +0.14%
==========================================
Files 46 46
Lines 2755 2771 +16
Branches 436 440 +4
==========================================
+ Hits 2568 2587 +19
+ Misses 107 105 -2
+ Partials 80 79 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The size check is driven by the active definition, so both directions need a guard: fields the definition does not list are not payload, and a field the definition lists still counts when the projected message no longer carries it (native and developer fields). The second direction is what stops a broken projection from passing as definition-sized. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f763-9923-75c7-b1ef-d1817be4902d
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.
What this fixes
WIRE validation compared
DataMessage.size— which counts every valid field, including fields that decode-time projection adds — withdefinition.defined_data_size. Component expansion (enhanced_speedfromspeed,enhanced_altitudefromaltitude) and the field 253 timestamp reconstructed for a compressed-timestamp record were therefore counted as wire payload, so the default validation path rejected files that round-trip byte-for-byte.validate_data_messagenow sums the payload from the active definition: a listed field counts at its own size, or at its definition size when it was cleared in memory (encode pads it with protocol-invalid bytes). A genuine size mismatch is still reported.Caller-visible changes
fit.validate()no longer reports false ERRORs on standard Garmin activities, andto_bytes(strict=True)/FitFileBuilder(strict=True)no longer refuse files that round-trip byte-for-byte.file_idno longer requiresserial_number. Garmin's FIT documentation marks the field optional, and Garmin's own activity files (Edge 1030 Plus, Forerunner 945 and Fenix 3 samples) omit it, carrying the device serial indevice_infoinstead.type,manufacturerandtime_createdare still required.Also: clearing a field after decode (for example
record.heart_rate = None) no longer trips the WIRE size check, because encode writes the protocol-invalid value at the definition's size.Before / after
sdk/Activity.fit—validate()findingsActivity.fit—to_bytes(strict=True)FitValidationError: record encodes 24 bytes but its definition requires 16FitFileBuilder(strict=True)over a decoded activityThe 35 remaining findings are the separate, documented gaps (developer-field metadata, unimplemented file types,
workout_stepambiguity,message_indexrequirements), not WIRE size errors.Tests
uv run pytest: 484 passed, 1 skipped (the skip is the live Garmin JS interop test, unchanged).uv run ruff check fit_tool: clean.uv run mypy: clean.News fragment:
news/+strict-wire-record-size.bugfix.