fix(pipeline): reject partially-consumed input in JSONWithVarExprs#22265
Open
ozpool wants to merge 1 commit intosmartcontractkit:developfrom
Open
fix(pipeline): reject partially-consumed input in JSONWithVarExprs#22265ozpool wants to merge 1 commit intosmartcontractkit:developfrom
ozpool wants to merge 1 commit intosmartcontractkit:developfrom
Conversation
The pipeline JSONWithVarExprs getter used a streaming json.Decoder that
read just one top-level token and returned. For a literal Ethereum
address in an ethtx task, the decoder happily read the leading 0 as a
complete JSON number, returned int64(0), and discarded the rest:
perform [type="ethtx"
from="0xAaAa...AAAA"
...]
fatal=true
run.FatalErrors=["from: AddressSliceParam: cannot convert int64: bad input for task"]
Because JSONWithVarExprs successfully returned int64(0), the next getter
in the From chain (NonemptyString) was never tried, and
AddressSliceParam.UnmarshalPipelineParam hit its default branch and
errored out.
Tighten JSONWithVarExprs to require the decoder to consume the full
input. After Decode returns, call jd.Token() once and require io.EOF;
anything else means trailing data, which the getter rejects with
ErrBadInput so the next getter in the chain gets a turn.
Adds table cases in getters_test.go covering the original bug shape
(literal Ethereum address, mixed alphanumeric, JSON value with
trailing junk).
Closes smartcontractkit#21768.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #21768.
The pipeline
JSONWithVarExprsgetter (core/services/pipeline/getters.go) uses a streamingjson.Decoderthat reads only one top-level token. For a literal Ethereum address in anethtxtask'sfromfield the decoder reads the leading0as a complete JSON number, returnsint64(0), and discards the rest of the address:Because
JSONWithVarExprssuccessfully returnsint64(0), the next getter in theFromchain (NonemptyString) is never tried, andAddressSliceParam.UnmarshalPipelineParamhits itsdefaultbranch and errors out.Issue author Beam already traced this in the report; root cause is that the decoder doesn't validate that it consumed the entire input.
Fix
Tighten
JSONWithVarExprsto require the decoder to consume the full input. Afterjd.Decode(...)returns, calljd.Token()once and requireio.EOF; anything else means there's trailing data, which the getter rejects withErrBadInputso the next getter in theFromchain (e.g.NonemptyString) gets its turn.Wire-observable behavior:
null) — unchanged. All existingTestGetters_JSONWithVarExprscases still pass.0xABCD...and similar partially-consumable inputs — now correctly fall through to the next getter, sofrom = "0x..."resolves viaNonemptyStringand theethtxtask succeeds.Tests
Added regression cases to the existing
TestGetters_JSONWithVarExprstable:0x1234567890abcdef1234567890abcdef12345678(full 20-byte address)0xdeadbeef123abc(number prefix + garbage suffix){"a":1} extra(valid JSON + trailing junk)All four assert
pipeline.ErrBadInput, matching the next-getter-falls-through contract.DB-backed tests in this package (
TestETHTxTask,TestETHCallTask) requireCL_DATABASE_URLand a Postgres test database, which I don't have set up locally; happy to add a focusedTestETHTxTask_FromLiteralAddressif a maintainer can either point me at the right setup or run those checks in CI.Diff