Skip to content

Commit

Permalink
Fixed negative length index crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed May 17, 2017
1 parent af89926 commit 0a92b8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Sources/BSON/Document+Subscripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ extension Document {
searchTree[part] = nil
}

let affectedPosition = relativeLength >= 0 ? meta.dataPosition : meta.dataPosition + relativeLength

for (key, startPosition) in searchTree where startPosition > affectedPosition {
for (key, startPosition) in searchTree where startPosition > meta.elementTypePosition {
searchTree[key] = startPosition + relativeLength
}

Expand Down
10 changes: 10 additions & 0 deletions Tests/BSONTests/BSONPublicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ final class BSONPublicTests: XCTestCase {
"maxKey": MaxKey()
]

func testRelativeLength() {
var document: Document = [
"_id": ObjectId(),
"henk": ["$db": "kaas", "$sap": "saus"]
]

document["henk"] = ObjectId()
XCTAssert(!document.validatesAsArray())
}

func testNullToNilInt() {
var doc: Document = [
"_id": Null(),
Expand Down

0 comments on commit 0a92b8a

Please sign in to comment.