rest: fix getutxos POST body decoding

bitcoin/bitcoin: PR #36385

3 suggestions

Earlier concerns neither republished nor resolved: 7 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · POST tests do not distinguish checkmempool values

The new functional tests would still pass if POST decoding consumed checkmempool but forced either value instead of using the supplied flag.

Location: test/functional/interface_rest.py:167 (head).

Details and suggested fix

Each successful body starts with b'\x01', and the queried transaction is already confirmed, so both coin views produce the same response. The old decoder also effectively forced true by reading the serialized-string length as the flag, although these tests do catch its separate outpoint misalignment. Extend the later unconfirmed-transaction fixture, before self.generate(self.nodes[0], 1), with .bin and .hex requests for [spending, spent] using both 0x00 and 0x01. Compare each decoded response with the binary URI response without or with /checkmempool, respectively. That fixture already establishes hit patterns of 01 and 10, so it would expose an ignored or inverted body flag without additional transaction setup.


Link

[suggestion] · POST body limits lack a 15/16-outpoint boundary test

The REST assertions do not pin acceptance at 15 body outpoints or distinguish bounded decoding from ordinary vector decoding followed by the existing size check.

Location: src/rest.cpp:1021 (head).

Details and suggested fix

The existing 15/20-outpoint calls use URI parameters and the helper's empty default body, while successful .bin and .hex bodies contain only two outpoints. The malformed binary body declares 34 outpoints but is truncated, so ordinary vector decoding would also return HTTP 400. Add complete body requests with 15 outpoints and compare their successful responses with the matching URI response. For complete 16-outpoint bodies, assert HTTP 400 and b"Parse error\r\n" in both formats. LIMITED_VECTOR throws before reserve; ordinary decoding would instead reach the later size guard and return Error: max outpoints exceeded (max: 15, tried: 16). Checking the text distinguishes loss of the bounded decoder, whereas status alone or a count-only truncated body does not.


Link

[suggestion] · ea2be74 bundles the decoding fix with independent input rejections

The decoding correction shares a commit with two independent input restrictions, complicating selective backports and attribution of new HTTP 400 responses.

Location: src/rest.cpp:1007 at ea2be74435e4 (commit) (commit).

Details and suggested fix

ea2be74435e4bd8d9792a8511cbca2ee516e8710 changes stream construction, rejects unread bytes, and replaces ParseHex with TryParseHex; its message already describes all three. Keep the raw-byte DataStream construction, its <span.h> include, and the two GET/POST equality changes together. Put trailing-byte rejection and malformed-hex rejection in separate following commits, each with its corresponding status assertions. The characterization commit 1b9bf04c42071d17087df82121823fb704a7fd8d already separates those assertion groups. Without the respective checks, trailing bytes still return success and malformed hex still becomes an empty successful request, matching those characterization expectations.

Keep the changes from f3228fa2ef8b9508cc5689a0649a24efb2bf2ff8 (bounded vector decoding), 5e6bf6c4dd95a9c5dfb1cc8ba3fe50675b1af072 (SpanReader), and 46029bd34fb8f29bf905f517423c9f8050ce3074 (zero-outpoint rejection) afterward in their current order. The last already isolates a comparable input restriction. This rearrangement leaves the final tree unchanged while allowing the decoding fix and each stricter rejection to be evaluated or selected independently.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

A 2015 change deliberately removed JSON-encoded getutxos parameters 'to avoid possible DoS scenarios,' while retaining JSON output. The same commit introduced the maximum of 15 queried outpoints.

Input restrictions and the 15-outpoint ceiling have an early resource-protection context, rather than being merely response-format preferences. This is relevant to applying the existing ceiling during body decoding. The inspected commit does not separately explain why 15 was chosen or require a particular oversized-request error message.

Source 1

Prior getutxos parsing changes expressly favored rejecting previously accepted malformed URI inputs: #30482 described truncated txid acceptance as brittle and proposed rejecting truncated or overlarge values; #30444 argued for rejecting signed outpoint indexes even though out-of-range indexes could harmlessly produce a nonexistent-UTXO result.

These are endpoint-specific precedents for distinguishing malformed requests from valid queries with no hits. They bear on compatibility judgment when malformed hex is newly rejected, but they concern URI fields and do not establish a decision about POST-body suffixes or empty vectors.

Source 1 · Source 2