mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-13 15:33:51 +02:00
test: cover failed CDBIterator::GetKey() deserialization
The upcoming change will replace the temporary owning `DataStream` inside `CDBIterator::GetKey()` with a borrowed reader over the current LevelDB key bytes. The copied `DataStream` currently insulates the iterator entry from a failed decode, so the optimization is only safe if a deserialization failure still returns `false` and leaves the same key/value readable afterward. Extend `dbwrapper_iterator` to read a one-byte key as a `uint16_t`. The read must fail, return `false`, and still allow the same key and value to be read afterward. This would fail if `GetKey()` stopped swallowing deserialization exceptions, or if a failed decode started consuming shared iterator state instead of only temporary reader state. Drop the dead `const_cast` in the test while here, since `dbw` is already non-const. Locking down that contract first makes the following `SpanReader` switch a behavior-preserving optimization.
This commit is contained in:
@@ -201,11 +201,15 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
|
||||
uint256 in2 = m_rng.rand256();
|
||||
dbw.Write(key2, in2);
|
||||
|
||||
std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator());
|
||||
std::unique_ptr<CDBIterator> it(dbw.NewIterator());
|
||||
|
||||
// Be sure to seek past the obfuscation key (if it exists)
|
||||
it->Seek(key);
|
||||
|
||||
// A failed key decode must not consume the current iterator entry.
|
||||
uint16_t key_too_large{0};
|
||||
BOOST_CHECK(!it->GetKey(key_too_large));
|
||||
|
||||
uint8_t key_res;
|
||||
uint256 val_res;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user