Fix truncation of last character of VIN by modifying decode_encoded_string() - #276
Open
gwillgues wants to merge 5 commits into
Open
Fix truncation of last character of VIN by modifying decode_encoded_string()#276gwillgues wants to merge 5 commits into
gwillgues wants to merge 5 commits into
Conversation
…coded_string function to use .replace() instead of .strip()
…ecode_encoded_string function to use .replace() instead of .strip()" This reverts commit 090b66a.
…ifying decode_encoded_string function to use .replace() instead of .strip()"" This reverts commit a10a12c.
…env var" This reverts commit 05514fc.
Author
|
@brendan-w Did you have a chance to review this? |
Author
|
@brendan-w Did you have a chance to review this? |
bkonick
added a commit
to WOT-Lemons/Lemongrass
that referenced
this pull request
Aug 7, 2026
VINs read over OBD-II were truncated before being used to tag telemetry.
python-obd 0.7.3 decodes Mode 09 strings with (obd/decoders.py:508):
d.strip().strip(b'\x00' b'\x01' b'\x02' b'\\x00' b'\\x01' b'\\x02')
Adjacent bytes literals concatenate, and the last three are the characters
backslash, x, 0, 1 and 2 rather than escapes, so the effective strip set is
{0x00, 0x01, 0x02, '0', '1', '2', '\', 'x'} -- applied to both ends. Any VIN
beginning or ending in 0, 1 or 2 was silently shortened, and one ending in
several such digits could lose them all. Confirmed against the ELM327
emulator, whose WP0ZZZ99ZTS390000 arrives as WP0ZZZ99ZTS39. The upstream fix
has been open as brendan-w/python-OBD#276 since May 2024 with no release
since, so this does not wait on it.
_decode_vin now reads the VIN from the raw response messages rather than
response.value, stripping only the control-byte padding, and scans every
message so a multi-ECU reply resolves to whichever yields a valid VIN.
_resolve_vin accepts an OBD-derived VIN only when it is a complete 17
alphanumeric characters, so a fragment can never become a tag and collide
with another car's prefix; anything shorter is discarded with a warning and
the configured telem.vin is used instead. A configured VIN is trusted as
given, and OBD remains the source of truth ahead of config.
The vin tag changes for any car whose VIN was being truncated, so its
telemetry appears under a new tag from the first run after deploying and
Grafana lists the old and new values as separate cars until the history is
reconciled.
Two emulator-backed integration tests (four cases, deselected by default)
exercise the real OBD path. The emulator serves a different sample VIN per
query, so they are parametrized across several rather than pinned to one and
assert the decoded value is a complete VIN strictly longer than the
library's.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.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.
When retrieving VIN via the following example code, I received 16 characters instead of the proper 17, and the trailing "0" in my VIN was truncated.
I modified decode_encoded_string() in decoders.py to use the .replace() function instead of .strip() to remove '\x00', '\x01', and '\x02', which resolved the issue in my testing.