Skip to content

Fix stack/heap buffer overflows in Zcash and Bitcoin builders, and prevent TWAnyAddressData crash on mismatched address type - #4801

Open
nikhil-gupta-tw wants to merge 6 commits into
masterfrom
fix/sec-issues-6
Open

Fix stack/heap buffer overflows in Zcash and Bitcoin builders, and prevent TWAnyAddressData crash on mismatched address type#4801
nikhil-gupta-tw wants to merge 6 commits into
masterfrom
fix/sec-issues-6

Conversation

@nikhil-gupta-tw

Copy link
Copy Markdown
Contributor

This pull request introduces important bug fixes and validation improvements across several transaction builder modules, as well as enhanced error handling in the address interface. The main changes ensure safer index handling for output insertion, stricter validation of transaction parameters, and improved robustness against exceptions.

Transaction output insertion safety:

  • Updated both Bitcoin/TransactionBuilder.h and Zen/TransactionBuilder.h to clamp the outputOpReturnIndex to the valid range, preventing out-of-bounds errors when inserting OP_RETURN outputs. [1] [2]

Parameter validation:

  • Added a check in Zcash/TransactionBuilder.h to verify that the provided branchId matches the expected size, returning an error if it does not, thus preventing invalid transaction construction.

Error handling:

  • Wrapped the TWAnyAddressData function in interface/TWAnyAddress.cpp with a try-catch block to return an empty data object if an exception occurs, improving stability and preventing crashes.

… buffer overflow from attacker-controlled TransactionPlan
… heap buffer overflow in UTXO transaction builder
…terminate when legacy Bitcoin address is used as BitcoinCash
@nikhil-gupta-tw
nikhil-gupta-tw requested review from a team and BSCSecChef as code owners June 12, 2026 08:32
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Binary size comparison

➡️ aarch64-apple-ios: 14.31 MB

➡️ aarch64-apple-ios-sim: 14.31 MB

➡️ aarch64-linux-android: 18.73 MB

➡️ armv7-linux-androideabi: 16.17 MB

➡️ wasm32-unknown-emscripten: 13.66 MB

@sergei-boiko-trustwallet sergei-boiko-trustwallet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BSCSecChef BSCSecChef left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use NU6BranchID here as default? -

std::copy(BlossomBranchID.begin(), BlossomBranchID.end(), tx.branchId.begin());

@sergei-boiko-trustwallet sergei-boiko-trustwallet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Just a few questions

Comment thread tests/chains/Zcash/TransactionCompilerTests.cpp
Comment thread tests/chains/Zcash/TWZcashTransactionTests.cpp
Comment thread src/Zcash/TransactionBuilder.h
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.

3 participants