Skip to content

ISSUE-4108: nfc: fix value-block BusFault and add unit test + test file generator - #4352

Open
herbenderbler wants to merge 1 commit into
flipperdevices:devfrom
herbenderbler:ISSUE-4108/nfc-bus-fault
Open

ISSUE-4108: nfc: fix value-block BusFault and add unit test + test file generator#4352
herbenderbler wants to merge 1 commit into
flipperdevices:devfrom
herbenderbler:ISSUE-4108/nfc-bus-fault

Conversation

@herbenderbler

Copy link
Copy Markdown

Summary

This PR fixes a crash during MIFARE Classic write flows when value blocks are encountered (reported as NFC BusFault in issue #4108).

Problem:

During write-condition evaluation, value blocks were flagged as is_value_block = true, but the write/read key type fields in the write context were not initialized on that path. Later logic consumed those fields, which could result in invalid enum usage and a BusFault during NFC write operations.

Affected code path:

Solution:

In the value-block branch of mf_classic_handler_check_write_conditions():

  • Select a valid key type (KeyA or KeyB) based on read access.
  • Initialize both key_type_read and key_type_write before any downstream use.
  • If neither key has read access, skip the block safely.
  • Set need_halt_before_write = false for value-block flow.
  • Transition to ReadBlock and exit early from this handler path to avoid falling through into non-value-block key derivation logic.

Also added:

Verification

Performed

  • Built firmware after fix (./fbt firmware_all) to verify integration/compilation.
  • Compiled the new unit test source directly with GCC to verify syntax and includes:
    • gcc -c -I. -Ilib -Ifuri -Itargets/f7/furi_hal -Itargets/f7/furi -Iapplications/debug/unit_tests/tests applications/debug/unit_tests/tests/nfc/mf_classic_write_value_block_test.c -o /tmp/test_compile.o
  • Manual static path validation of value-block branch to confirm key initialization invariants.

Recommended/Prepared

  • Unit test execution in unit_tests app set.
  • On-device NFC write validation with MIFARE Classic cards (including value-block scenarios) using generated test files.

Checklist (For Reviewer)

  • PR has description of feature/bug or link to Confluence/Jira task
  • Description contains actions to verify feature/bugfix
  • I've built this code, uploaded it to the device and verified feature/bugfix

@herbenderbler herbenderbler changed the title nfc: fix value-block BusFault and add unit test + test file generator ISSUE-4108: nfc: fix value-block BusFault and add unit test + test file generator Mar 12, 2026
@herbenderbler
herbenderbler marked this pull request as ready for review March 12, 2026 05:02
@akrylysov

akrylysov commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

I tried building a firmware with this change included and it unfortunately didn't fix the crash. It's not impossible the crash I'm seeing is a different bug.

@herbenderbler

Copy link
Copy Markdown
Author

I tried building a firmware with this change included and it unfortunately didn't fix the crash. It's not impossible the crash I'm seeing is a different bug.

Thanks for that feedback. Let me take another pass at it. How can I replicate the crash/error you received? Would you mind dropping more details in this thread?

@akrylysov

Copy link
Copy Markdown
Contributor

I spent some time digging into my crash and it seems it was a caused by a different bug #4362

@turbospok turbospok added AI-generated To mark changes made via AI tools NFC NFC-related labels Jun 26, 2026
@turbospok turbospok moved this from Todo to Backlog in Flipper Zero Firmware Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-generated To mark changes made via AI tools NFC NFC-related

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants