Skip to content

Commit 983c6a5

Browse files
LEN-4572: Fix for parsing zero-length maps (#7)
1 parent bb9c965 commit 983c6a5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

source/Cborg.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ bool Cborg::getCBOR(const uint8_t** pointer, uint32_t* length)
8181
units = maxOf(units);
8282
}
8383

84+
// Handle a zero-length map or array
85+
if (units == 0) {
86+
*length = progress;
87+
return true;
88+
}
89+
8490
// iterate through cbor encoded buffer
8591
// stop when maximum length is reached or
8692
// the current container is finished
@@ -237,6 +243,11 @@ uint32_t Cborg::getCBORLength()
237243
units = maxOf(units);
238244
}
239245

246+
// Handle a zero-length map or array
247+
if (units == 0) {
248+
return progress;
249+
}
250+
240251
// iterate through cbor encoded buffer
241252
// stop when maximum length is reached or
242253
// the current container is finished
@@ -895,7 +906,7 @@ Cborg Cborg::at(std::size_t index) const
895906
int32_t units = head.getValue();
896907
units = (simple == CborBase::TypeIndefinite) ? maxOf(units) : units;
897908

898-
// only continue if container is Cbor Map, not empty, and index is within bounds
909+
// only continue if container is Cbor Array, not empty, and index is within bounds
899910
if ((type != CborBase::TypeArray) || (units == 0) || ((int32_t) index >= units))
900911
{
901912
return Cborg(NULL, 0);

0 commit comments

Comments
 (0)