refactor: Use SpanReader over DataStream
What changed, and why it matters
This is a small internal code cleanup in Bitcoin Core's database wrapper. It replaces one temporary data-reading helper (DataStream) with another (SpanReader) and reuses an existing mutable buffer to avoid copying data during de-obfuscation. There is no visible security bug or behavior change in the diff.
No security action required. Treat as a normal code-quality refactor during review.
Security signals we found
No memory-safety issues introduced: the span remains bounded to the existing `strValue` buffer.
No change to cryptographic operations: the same `m_obfuscation` XOR is applied to the same bytes.
No input validation or trust-boundary changes.
No secrets or authentication logic modified.
Evidence from the diff
The commit refactors CDBWrapper::Read in src/dbwrapper.h. Previously a DataStream was constructed from a read-only byte span of *strValue, then the obfuscation key was XORed into that stream, and the value was deserialized. The patch instead creates a writable std::span over the same buffer, applies obfuscation in place, and uses SpanReader for deserialization. The functional effect is identical: the same obfuscation is applied and the same bytes are deserialized. The change merely removes a redundant copy.
Changed components
src/dbwrapper.hCDBWrapper::ReadInspect captured patch +2 / −2
diff --git a/src/dbwrapper.h b/src/dbwrapper.h
index b2ce67c7..2eee6c1c 100644
--- a/src/dbwrapper.h
+++ b/src/dbwrapper.h
@@ -214,9 +214,9 @@ public:
return false;
}
try {
- DataStream ssValue{MakeByteSpan(*strValue)};
+ std::span ssValue{MakeWritableByteSpan(*strValue)};
m_obfuscation(ssValue);
- ssValue >> value;
+ SpanReader{ssValue} >> value;
} catch (const std::exception&) {
return false;
}
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.