Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Mutation: diff --git a/src/serialize.h b/src/serialize.h
index 9a1ff56ec4..81d675c3c0 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -358,5 +358,2 @@ uint64_t ReadCompactSize(Stream& is, bool range_check = true)
}
- if (range_check && nSizeRet > MAX_SIZE) {
- throw std::ios_base::failure("ReadCompactSize(): size too large");
- }
return nSizeRet; |
|
Quite nuanced to track down! Fixing this will help with coverage determinism. Concept ACK |
|
If this is useful to anyone, here a script that reproduces the non-determinism in coverage. With this PR applied it is fixed. Script#!/usr/bin/env bash
# Coverage check for the src/serialize.h "ReadCompactSize(): size too large" guard.
# Builds with LLVM coverage, then runs the unit suite's serialisation cases and one
# functional test per run, and reports the guard's execution count for each run.
# Run from the bitcoin checkout root. Needs clang, cmake, python3, llvm-profdata and
# llvm-cov on PATH. Usage: ./guard-flip.sh [runs] (default 8)
set -eu
cd "$(dirname "$0")"
RUNS=${1:-8}
echo 'Building bitcoin with coverage'
cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-DAPPEND_CFLAGS="-fprofile-instr-generate -fcoverage-mapping" \
-DAPPEND_CXXFLAGS="-fprofile-instr-generate -fcoverage-mapping" \
-DAPPEND_LDFLAGS="-fprofile-instr-generate" \
-DBUILD_GUI=OFF -DBUILD_BENCH=OFF -DBUILD_FUZZ_BINARY=OFF >/dev/null
cmake --build build -j"$(nproc)" --target bitcoind bitcoin-cli test_bitcoin >/dev/null
L=$(grep -n 'ReadCompactSize(): size too large' src/serialize.h | cut -d: -f1)
echo "guard line: src/serialize.h:$L"
counts=()
for i in $(seq "$RUNS"); do
d=$(mktemp -d)
LLVM_PROFILE_FILE=$d/u_%m_%p.profraw ./build/bin/test_bitcoin --run_test=serialize_tests >/dev/null 2>&1 || true
LLVM_PROFILE_FILE=$d/f_%m_%p.profraw TMPDIR=/tmp \
python3 build/test/functional/test_runner.py wallet_create_tx.py --randomseed=1234 >/dev/null 2>&1 || true
llvm-profdata merge -o "$d/p.profdata" "$d"/*.profraw 2>/dev/null
llvm-cov export --format=lcov --object=build/bin/bitcoind --object=build/bin/test_bitcoin \
--instr-profile="$d/p.profdata" > "$d/info" 2>"$d/err" || true
c=$(awk -F'[:,]' -v l="$L" '/^SF:.*serialize\.h$/ {s=1} s && $1=="DA" && $2==l {print $3; exit}' "$d/info")
[ -n "$c" ] || { echo "run $i: no DA record for line $L, see $d/err" >&2; exit 2; }
counts+=("$c")
echo "run $i: $c"
rm -rf "$d"
done
echo "counts: ${counts[*]}"
if printf '%s\n' "${counts[@]}" | grep -qx 0; then
echo "FLIPS: the guard was left uncovered on at least one run"
else
echo "NO FLIPS: the guard was covered on every run"
fi
|
An alternative would be to just replace the code with |
* Replace the isCanonicalException impl with the normal pattern of HasReason * Drop the confusing std::vector::size_t, becasue ReadCompactSize returns an u64.
fa3f8f9 to
fa01715
Compare
|
thx, took all nits |
|
ACK fa01715 |
Dropt the extaneous 15 lines. Can be reviewed with the git option --word-diff-regex=.
fa01715 to
fa5aabe
Compare
|
reACK fa5aabe |

Currently there is no test coverage for oversized CompactSize. This is fine, because a vector this large will already be rejected earlier by the P2P transport payload size check.
However, it would be good to still add test coverage: