GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — v5: plumbing: format decoder input bounds and contracts by hiddeco · Pull Request #2125 · go-git/go-git Conversation
Member
Backport of #2119
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsApply the size formula canonical Git uses in `packfile.c:load_idx`
[1]: for an idx v2 file with `nr` objects and hash size `hashsz`,
the on-disk length must lie within `[minSize, maxSize]` where
minSize = 8 + 4*256 + nr*(hashsz+8) + 2*hashsz
maxSize = minSize + (nr-1)*8 when nr > 0
Overflow-checked multiplication rejects inputs whose claimed object
count overflows the formula rather than wrapping into a smaller
value.
To keep the public `NewDecoder(io.Reader)` signature compatible on
v5, the decoder probes for an unexported `statInput` interface
(`Stat() (fs.FileInfo, error)`) at the top of `Decode`. Inputs that
satisfy it have the size formula applied; arbitrary readers retain
the pre-existing behaviour of erroring out at the truncated-payload
boundary. The two production call sites in `storage/filesystem`
pass a `billy.File`; on `osfs` that wraps `*os.File`, so the
formula does run there.
[1]: https://github.com/git/git/blob/v2.54.0/packfile.c#L232-L258
Backport of go-git#2119.
Assisted-by: Claude Opus 4.7
Signed-off-by: Hidde Beydals <[email protected]>
pjbgf
reviewed
Uh oh!
There was an error while loading. Please reload this page.
pjbgf
reviewed
Uh oh!
There was an error while loading. Please reload this page. A packfile object header carries the object's uncompressed size, and a well-formed packfile never produces more inflated bytes than that value. Enforce this structural invariant at every site that consumes the inflated stream and surface mismatches as `ErrInflatedSizeMismatch`. Both `Scanner.NextObject` and `Scanner.ReadObject` capture the declared length from the most recent `pendingObject` before clearing it, then thread that bound into `copyObject`. The shared `copyObject(w, declaredSize)` wraps its writer in a new `boundedWriter` when a positive size is supplied, so an overrun returns the legal prefix alongside `ErrInflatedSizeMismatch` rather than being silently appended. Callers in `parser.go` and `packfile.go` go through `NextObject`, so they pick up the bound without further changes; for delta entries the declared length is the size of the delta instruction stream, not the resolved result, which matches what these call sites already pass through. The lazy `FSObject.Reader` big-object path returns a new `boundedReadCloser` that wraps the underlying zlib-backed reader. It builds on `io.LimitedReader` with the standard overrun-detection trick — request `limit + 1` bytes and treat the sentinel byte as an explicit signal — so an `io.ReadAll` on an opened object cannot stream past the declared size. The bound is `o.size`, the resolved object size, which matches what the caller is reading regardless of whether the underlying entry is a non-delta or delta-resolved object. The type and its constructor are unexported for now; they can be promoted once a stable use case outside the package emerges. These changes do not reject any conforming pack. Backport of go-git#2119. Assisted-by: Claude Opus 4.7 Signed-off-by: Hidde Beydals <[email protected]> `Reader` defines a two-phase contract: callers must invoke `Header` to consume the loose-object type and size fields, after which the internal `multi` reader and `hasher` are initialised. Calling `Read` or `Hash` before a successful `Header` accessed uninitialised fields and would panic on `r.multi.Read` / `r.hasher.Sum`. Make the contract explicit: `Read` returns the new `ErrHeaderNotRead` sentinel when `Header` has not been called successfully. `Hash` returns `plumbing.ZeroHash` in the same situation. Both methods guard on `r.multi == nil`, which `prepareForRead` sets on the first successful `Header` call. Two unit tests pin the behaviour: `TestReaderReadBeforeHeader` asserts that `Read` returns `ErrHeaderNotRead` and `Hash` returns `ZeroHash`; `TestReaderReadAfterHeaderError` calls `Read` after `Header` has returned an error. Backport of go-git#2119. Assisted-by: Claude Opus 4.7 Signed-off-by: Hidde Beydals <[email protected]>
hiddeco
force-pushed
the
v5/format-input-bounds
branch
from
fdf4dd2 to
aeaa125
Compare
pjbgf
approved these changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hiddeco Thanks for working on this. 🙇
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page.
Maks1mS
pushed a commit
to stplr-dev/stplr
that referenced
this pull request
This PR contains the following updates: | Package | Type | Update | Change | OpenSSF | |---|---|---|---|---| | [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) | require | patch | `v5.19.0` → `v5.19.1` | [](https://securityscorecards.dev/viewer/?uri=github.com/go-git/go-git) | --- >
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |