json: report integer duration overflow against time.Duration#167
Open
sueun-dev wants to merge 1 commit into
Open
json: report integer duration overflow against time.Duration#167sueun-dev wants to merge 1 commit into
sueun-dev wants to merge 1 commit into
Conversation
decodeDuration parses integer durations with parseInt(b, durationType), but on error it returned inputError(b, int32Type) and then checked v < math.MinInt64 || v > math.MaxInt64. v is an int64, so that branch is unreachable (staticcheck SA4003, the lint in segmentio#150), and both error paths reported int32 instead of time.Duration. time.Duration is backed by int64, so propagate the parseInt error the same way decodeInt64 does. Add a regression test. Fixes segmentio#150
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.
decodeDurationparses integer durations withparseInt(b, durationType), but on error it returnedinputError(b, int32Type)and then checkedv < math.MinInt64 || v > math.MaxInt64.vis anint64, so that branch is unreachable (staticcheck SA4003, the lint reported in #150), and both error paths reportedint32instead oftime.Duration.Decoding an integer that overflows int64 into a
time.Durationfield showed this:time.Durationis backed byint64, sodecodeDurationcan propagate theparseInterror the same waydecodeInt64does, with no separate bounds check. Added a regression test;go test ./...passes and staticcheck no longer flags the line.Fixes #150