Skip to content

Limit binary fragment size during applies#77

Merged
bluekeyes merged 2 commits into
masterfrom
apply-fragement-limit
Jul 18, 2026
Merged

Limit binary fragment size during applies#77
bluekeyes merged 2 commits into
masterfrom
apply-fragement-limit

Conversation

@bluekeyes

Copy link
Copy Markdown
Owner

Applying a binary fragment can use a lot of memory in two ways:

  1. Inflating a large amount of literal data
  2. Processing a delta instruction stream with many copy operations

Clients could theoretically protect against the first by checking fragment sizes for all binary fragments before the apply, but there's no way to protect against the second case except by decoding the delta instruction stream. And because the first case used to happen at parse time, there are no existing clients that check this before applying.

Fix both issues by enforcing a maximum binary fragment size. The default value is 100MiB, which matches GitHub.com's default maximum file size. Clients can adjust or disabled this limit by passing new option functions to Apply, NewTextApplier, and NewBinaryApplier.

Finally, fix an encoding issue in the bin.go helper utility by using the standard BinaryFragment string representation instead of implementing the encoding directly with bad wrapping logic. This was required to generate the test patches for applies over the limit. The .hex files are not used directly by the test, but provide the source input for the patches as processed by bin.go.

Applying a binary fragment can use a lot of memory in two ways:

1. Inflating a large amount of literal data
2. Processing a delta instruction stream with many copy operations

Clients could theoretically protect against the first by checking
fragment sizes for all binary fragments before the apply, but there's no
way to protect against the second case except by decoding the delta
instruction stream. And because the first case used to happen at parse
time, there are no existing clients that check this before applying.

Fix both issues by enforcing a maximum binary fragment size. The default
value is 100MiB, which matches GitHub.com's default maximum file size.
Clients can adjust or disabled this limit by passing new option
functions to Apply, NewTextApplier, and NewBinaryApplier.

Finally, fix an encoding issue in the bin.go helper utility by using the
standard BinaryFragment string representation instead of implementing
the encoding directly with bad wrapping logic. This was required to
generate the test patches for applies over the limit. The `.hex` files
are not used directly by the test, but provide the source input for the
patches as processed by `bin.go`.
@bluekeyes
bluekeyes merged commit 51e5b1f into master Jul 18, 2026
1 check passed
@bluekeyes
bluekeyes deleted the apply-fragement-limit branch July 18, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant