Skip to content

Commit

Permalink
fix: bignum parsed as Value
Browse files Browse the repository at this point in the history
Fixes: #31

Signed-off-by: Ahmed Charles <[email protected]>
  • Loading branch information
ahmedcharles committed Feb 18, 2024
1 parent 779edb4 commit 0468cd4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
15 changes: 15 additions & 0 deletions ciborium-ll/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,21 @@ mod tests {
Header::Break,
],
),
(
"c340",
&[
Header::Tag(3),
Header::Bytes(Some(0)),
],
),
(
"c35fff",
&[
Header::Tag(3),
Header::Bytes(None),
Header::Break,
],
),
];

for (bytes, headers) in data {
Expand Down
10 changes: 2 additions & 8 deletions ciborium/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,8 @@ where
let header = self.decoder.pull()?;
self.decoder.push(header);

// If it is bytes, capture the length.
let len = match header {
Header::Bytes(x) => x,
_ => None,
};

match (tag, len) {
(tag::BIGPOS, Some(len)) | (tag::BIGNEG, Some(len)) if len <= 16 => {
match tag {
tag::BIGPOS | tag::BIGNEG => {
let result = match self.integer(Some(Header::Tag(tag)))? {
(false, raw) => return visitor.visit_u128(raw),
(true, raw) => i128::try_from(raw).map(|x| x ^ !0),
Expand Down
2 changes: 2 additions & 0 deletions ciborium/tests/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ macro_rules! map {
case(Enum::Newtype(45), cbor!({"Newtype" => 45}).unwrap(), "a1674e657774797065182d", false, same), // Not In RFC
case(Enum::Tuple(56, 67), cbor!({"Tuple" => [56, 67]}).unwrap(), "a1655475706c658218381843", false, same), // Not In RFC
case(Enum::Struct { first: 78, second: 89 }, cbor!({ "Struct" => { "first" => 78, "second" => 89 }}).unwrap(), "a166537472756374a2656669727374184e667365636f6e641859", false, same), // Not In RFC
case(-1i8, val!(-1), "c340", true, same), // Not In RFC
case(-1i8, val!(-1), "c35fff", true, same), // Not In RFC
)]
fn codec<'de, T: Serialize + Clone, V: Debug + PartialEq + DeserializeOwned, F: Fn(T) -> V>(
input: T,
Expand Down

0 comments on commit 0468cd4

Please sign in to comment.