Skip to content

Commit

Permalink
Merge pull request #1530 from evoskuil/master
Browse files Browse the repository at this point in the history
Do not allow nullptr witness stack elements.
  • Loading branch information
evoskuil authored Aug 23, 2024
2 parents 5ff7c3e + 099a3b4 commit 2e2929d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/bitcoin/system/stream/streamers/byte_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class byte_reader
/// -----------------------------------------------------------------------
/// cptr/raw overrides return nullptr if reader is or becomes invalid.
/// Non-null raw return must be destroyed using reader's allocator/arena.
/// Null raw return implies invalidated stream.

/// Read all remaining bytes to chunk.
data_chunk read_bytes() NOEXCEPT override;
Expand Down
2 changes: 2 additions & 0 deletions src/chain/operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ void operation::assign_data(reader& source) NOEXCEPT
{
code_ = any_invalid;
source.set_position(start);

// An invalid source.read_bytes_raw returns nullptr.
data_.reset(POINTER(data_chunk, allocator, source.read_bytes_raw()));
}

Expand Down
8 changes: 8 additions & 0 deletions src/chain/witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ void witness::assign_data(reader& source, bool prefix) NOEXCEPT

for (size_t element = 0; element < count; ++element)
{
// If read_bytes_raw returns nullptr invalid source is implied.
const auto size = source.read_size(max_block_weight);
const auto bytes = source.read_bytes_raw(size);
if (is_null(bytes))
break;

stack_.emplace_back(POINTER(data_chunk, allocator, bytes));
size_ = element_size(size_, stack_.back());
}
Expand All @@ -186,8 +190,12 @@ void witness::assign_data(reader& source, bool prefix) NOEXCEPT
{
while (!source.is_exhausted())
{
// If read_bytes_raw returns nullptr invalid source is implied.
const auto size = source.read_size(max_block_weight);
const auto bytes = source.read_bytes_raw(size);
if (is_null(bytes))
break;

stack_.emplace_back(POINTER(data_chunk, allocator, bytes));
size_ = element_size(size_, stack_.back());
}
Expand Down

0 comments on commit 2e2929d

Please sign in to comment.