Conversation
Endika
requested review from
956MB,
HaxSam,
MatthewKuKanich,
Sil333033 and
WillyJL
as code owners
July 28, 2026 10:52
This was referenced Jul 28, 2026
Endika
force-pushed
the
fix-t4t-write-offset
branch
from
September 10, 2026 15:58
3157929 to
8b395b1
Compare
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.
Description
In
type_4_tag_listener_iso_write(), a write that starts inside the two-byte NLEN field consumeswrite_len = sizeof(uint16_t) - offsetbytes for that field. The payload pointer is then advanced byoffsetinstead:offsethas already been reassigned tosizeof(uint16_t)on the line above, sodataalways moves forward by 2 regardless of how much was actually consumed.With
offset == 0the two agree (write_lenis 2), which is why this goes unnoticed. Withoffset == 1only one byte belongs to NLEN, so:lcwas only reduced by 1, so the copy runs one byte past the end of the reader's APDU data.offsetcomes straight from the command header (offset = (p1 << 8) + p2), so a reader only has to sendP1 = 0x00,P2 = 0x01to reach it.Fix
Advance by the number of bytes actually consumed:
Behaviour at
offset == 0is unchanged, sincewrite_lenis 2 there.Additional fixes ported from unleashed
While reviewing the fix above in DarkFlippers/unleashed-firmware#1049, @mishamyte found four more ways a reader can crash a Flipper emulating a Type 4 Tag and fixed them in DarkFlippers/unleashed-firmware#1051, stacked on top. This repo carries the same code, so it carries the same crashes. Both of his commits are included here with their original authorship.
Verification
./fbt firmware_allbuilds clean (f7-firmware-C).This file is byte-identical between this repo and DarkFlippers/unleashed-firmware (blob
7da6fadc), and the fixed file is likewise identical to the one in DarkFlippers/unleashed-firmware#1049 (blob84ccfb9b) — so this is the same change, not a re-derivation.