Skip to content

primitives: further tighten memory allocations in witness decoder #5258

@nyonson

Description

@nyonson

A follow up from #5239 to improve how WitnessDecoder::resize_if_needed caps its memory allocation. Original comments from @apoelstra:

I also think that somewhere we should be capping required_len to 20 Mb, which I think is the maximum amount it can be for a valid witness (one with 4 million entries, 3999999 of which are 0-length and the other one 4 million bytes).

and

This can overflow on a 16-bit machine. We should clamp new_len to usize::MAX

This may be influenced by what direction @jrakibi takes in #5177.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions