Skip to content

Commit

Permalink
Removed the ArraySizeLimit.
Browse files Browse the repository at this point in the history
It's not useful anymore because:
1. There used to be bugs in the library that allowed the "path" field of
the "move" and "copy" operations to refer to arbitrarily large index of
an existing array. Now the bugs are fixed, the two operations can at
most increase the length of any _existing_ array by 1, by appending to the
end.

2. The "add" and "replace" operation can create large new arrays.
However, for these two operations, the patch MUST contain the "value",
thus the caller of this library can cap the size by limiting the size of the
patch.

3. The "copy" operations can copy existing large array, but users can
control the size increase by setting AccumulatedCopySizeLimit.
  • Loading branch information
Chao Xu committed Feb 3, 2019
1 parent 500d67a commit bbf30d6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,10 @@ go get -u github.com/evanphx/json-patch
functionality can be disabled by setting `jsonpatch.SupportNegativeIndices =
false`.

* There is a global configuration variable `jsonpatch.ArraySizeLimit`, which
limits the length of any array the patched object can have. It defaults to 0,
which means there is no limit.

<<<<<<< HEAD
* There is a global configuration variable `jsonpatch.ArraySizeAdditionLimit`,
which limits the increase of array length caused by each operation. It
defaults to 0, which means there is no limit.

* There is a global configuration variable `jsonpatch.AccumulatedCopySizeLimit`,
which limits the total size increase in bytes caused by "copy" operations in a
patch. It defaults to 0, which means there is no limit.

=======
>>>>>>> Since that the "set" method is now only called to implement the
## Create and apply a merge patch
Given both an original JSON document and a modified JSON document, you can create
a [Merge Patch](https://tools.ietf.org/html/rfc7396) document.
Expand Down
4 changes: 0 additions & 4 deletions patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (
// allowing negative indices to mean indices starting at the end of an array.
// Default to true.
SupportNegativeIndices bool = true
ArraySizeLimit int = 0
// AccumulatedCopySizeLimit limits the total size increase in bytes caused by
// "copy" operations in a patch.
AccumulatedCopySizeLimit int64 = 0
Expand Down Expand Up @@ -390,9 +389,6 @@ func (d *partialArray) add(key string, val *lazyNode) error {
}

sz := len(*d) + 1
if ArraySizeLimit > 0 && sz > ArraySizeLimit {
return fmt.Errorf("Unable to create array of size %d, limit is %d", sz, ArraySizeLimit)
}

ary := make([]*lazyNode, sz)

Expand Down
7 changes: 2 additions & 5 deletions patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,16 @@ var BadCases = []BadCase{
}

// This is not thread safe, so we cannot run patch tests in parallel.
func configureGlobals(arraySizeLimit int, accumulatedCopySizeLimit int64) func() {
oldArraySizeLimit := ArraySizeLimit
func configureGlobals(accumulatedCopySizeLimit int64) func() {
oldAccumulatedCopySizeLimit := AccumulatedCopySizeLimit
ArraySizeLimit = arraySizeLimit
AccumulatedCopySizeLimit = accumulatedCopySizeLimit
return func() {
ArraySizeLimit = oldArraySizeLimit
AccumulatedCopySizeLimit = oldAccumulatedCopySizeLimit
}
}

func TestAllCases(t *testing.T) {
defer configureGlobals(1000, int64(100))()
defer configureGlobals(int64(100))()
for _, c := range Cases {
out, err := applyPatch(c.doc, c.patch)

Expand Down

0 comments on commit bbf30d6

Please sign in to comment.