Skip to content

Commit

Permalink
fixed issue #109
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteemann committed Jan 27, 2022
1 parent 3cfdb0b commit 94e36ad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Validator.cpp
Expand Up @@ -259,11 +259,14 @@ void Validator::validateCompactArray(uint8_t const* ptr, std::size_t length) {
throw Exception(Exception::ValidatorInvalidLength, "Array length value is out of bounds");
}
++p;

// validate the array members
uint8_t const* e = p;
p = data;
while (nrItems-- > 0) {
if (p >= e) {
throw Exception(Exception::ValidatorInvalidLength, "Array items number is out of bounds");
}
validate(p, e - p, true);
p += Slice(p).byteSize();
}
Expand Down
28 changes: 28 additions & 0 deletions tests/testsValidator.cpp
Expand Up @@ -1830,6 +1830,34 @@ TEST(ValidatorTest, ArrayCompactNrItemsWrong3) {
ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}

TEST(ValidatorTest, ArrayCompactNrItemsExceedsBytesize) {
std::string const value("\x13\x06\x42\x40\x40\x02", 6);

Validator validator;
ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}

TEST(ValidatorTest, ArrayCompactMemberExceedsBytesize1) {
std::string const value("\x13\x06\x43\x40\x40\x02", 6);

Validator validator;
ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}

TEST(ValidatorTest, ArrayCompactMemberExceedsBytesize2) {
std::string const value("\x13\x06\x44\x40\x40\x02", 6);

Validator validator;
ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}

TEST(ValidatorTest, ArrayCompactMemberExceedsBytesize3) {
std::string const value("\x13\x06\x45\x40\x40\x02", 6);

Validator validator;
ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}

TEST(ValidatorTest, ArrayCompactManyEntries) {
Builder b;
b.openArray(true);
Expand Down

0 comments on commit 94e36ad

Please sign in to comment.