Skip to content

fix: implement self-healing fallback parser for buffer size misalignment#3

Merged
vkaylee merged 1 commit into
masterfrom
fix/buffer-size-parsing
Jun 21, 2026
Merged

fix: implement self-healing fallback parser for buffer size misalignment#3
vkaylee merged 1 commit into
masterfrom
fix/buffer-size-parsing

Conversation

@vkaylee

@vkaylee vkaylee commented Jun 21, 2026

Copy link
Copy Markdown
Owner

fix: implement self-healing fallback parser for buffer size misalignment

When the ZK device returns CMD_PREPARE_DATA with a size at offset 0 but with trailing garbage bytes (making the payload length >= 5), the parser incorrectly shifts and reads the size at offset 1. This causes the size parsing to fail with "Buffered response size exceeds maximum".

We implement a robust, self-healing parser that tries offset 1 first (standard), and automatically falls back to offset 0 if the parsed size at offset 1 is invalid (exceeds MAX_RESPONSE_SIZE) while offset 0 is valid. Added integration test test_prepare_buffer_offset_misalignment_tcp to verify this behavior.

When the ZK device returns CMD_PREPARE_DATA with a size at offset 0 but with trailing garbage bytes (making the payload length >= 5), the parser incorrectly shifts and reads the size at offset 1. This causes the size parsing to fail with "Buffered response size exceeds maximum".

We implement a robust, self-healing parser that tries offset 1 first (standard), and automatically falls back to offset 0 if the parsed size at offset 1 is invalid (exceeds MAX_RESPONSE_SIZE) while offset 0 is valid. Added integration test `test_prepare_buffer_offset_misalignment_tcp` to verify this behavior.
@vkaylee
vkaylee merged commit 1504759 into master Jun 21, 2026
1 check passed
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.

1 participant