Skip to content

wire: Clear tx inputs/outputs before deserialize.#3621

Merged
davecgh merged 1 commit intodecred:masterfrom
davecgh:wire_nil_tx_ins_outs
Feb 25, 2026
Merged

wire: Clear tx inputs/outputs before deserialize.#3621
davecgh merged 1 commit intodecred:masterfrom
davecgh:wire_nil_tx_ins_outs

Conversation

@davecgh
Copy link
Copy Markdown
Member

@davecgh davecgh commented Feb 25, 2026

The code that handles deserializing transaction scripts by way of the free list cleans up in the event of error by returning the non-nil scripts to the free list to avoid leaking them.

This is making an implicit (and undocumented) assumption that it is only deserializing into empty instances and therefore any non-nil scripts in the inputs and outputs in the event of a failed deserialization came from the free list. The consequence of that is that it is possible that any slices that were set by the caller prior to a failed deserialization could incorrectly be returned to the free list and ultimately get clobbered later.

While this is not an issue for dcrd since it never deserializes into non-empty instances, there is no guarantee that is true for all callers.

In order to ensure safety for all callers, this nils the input and output slices prior to deserializing anything in order to ensure the aforementioned assumption is always satisfied.

@davecgh davecgh added this to the 2.2.0 milestone Feb 25, 2026
@davecgh davecgh force-pushed the wire_nil_tx_ins_outs branch from 72e038a to c6161f1 Compare February 25, 2026 23:01
The code that handles deserializing transaction scripts by way of the
free list cleans up in the event of error by returning the non-nil
scripts to the free list to avoid leaking them.

This is making an implicit (and undocumented) assumption that it is only
deserializing into empty instances and therefore any non-nil scripts in
the inputs and outputs in the event of a failed deserialization came
from the free list.  The consequence of that is that it is possible that
any slices that were set by the caller prior to a failed deserialization
could incorrectly be returned to the free list and ultimately get
clobbered later.

While this is not an issue for dcrd since it never deserializes into
non-empty instances, there is no guarantee that is true for all callers.

In order to ensure safety for all callers, this nils the input and
output slices prior to deserializing anything in order to ensure the
aforementioned assumption is always satisfied.
@davecgh davecgh force-pushed the wire_nil_tx_ins_outs branch from c6161f1 to 8ac97cb Compare February 25, 2026 23:43
@davecgh davecgh merged commit 8ac97cb into decred:master Feb 25, 2026
33 checks passed
@davecgh davecgh deleted the wire_nil_tx_ins_outs branch February 26, 2026 00:15
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