Skip to content

Secure DFU: handle an error reply to Calculate Checksum instead of throwing in the GATT callback - #529

Open
niklavsBariss wants to merge 1 commit into
nordicsemi:mainfrom
mitigate-dev:fix/secure-dfu-checksum-error-reply
Open

niklavsBariss wants to merge 1 commit into
nordicsemi:mainfrom
mitigate-dev:fix/secure-dfu-checksum-error-reply

Conversation

@niklavsBariss

Copy link
Copy Markdown

Problem

The Calculate Checksum branch of SecureBluetoothCallback.onCharacteristicChanged reads the offset and CRC without checking the status byte. An error reply (60 03 <status>) has neither, so getIntValue returns null and the callback throws. BluetoothGatt swallows it, the reply is lost, and the upload waits until the target drops the link.

How it shows up

12:41:10.915  W BluetoothGatt: Unhandled exception in callback
12:41:10.915  W BluetoothGatt: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
12:41:10.915  W BluetoothGatt:   at no.nordicsemi.android.dfu.SecureDfuImpl$SecureBluetoothCallback.onCharacteristicChanged(SecureDfuImpl.java:111)
12:43:16.129  W DfuBaseService: Target device disconnected with status: 8

Fix

This PR makes an error reply to Calculate Checksum fail the upload with that remote error instead of stalling it. An error goes to the waiting thread like other replies, so readChecksum reports it as a RemoteDfuException. A reply too short for its status is an invalid response: readChecksum reads an extended error's code from response[3], and an exception there on the service thread would crash the app. The fields come from the notification's value, which on Android 13+ the characteristic isn't guaranteed to match.

Verified

Xiaomi 14T (Android 16), 2.4.2 from source, with a fault that replaces one checksum reply with 60 03 08. Without the change, the NPE and a stalled upload; with it, Receiving Checksum failed (error 8): OPERATION NOT PERMITTED and a clean DFU_FAILED. The short-extended-error check is compile-checked only.

@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

2 participants