Skip to content

Commit 151d2c4

Browse files
committed
Fix smallest CBOR integer
1 parent a3b2a64 commit 151d2c4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pytests/test_dag_cbor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,13 @@ def test_recursion_limit_exceed_on_nested_maps() -> None:
135135
libipld.decode_dag_cbor(dag_cbor)
136136

137137
assert 'in DAG-CBOR decoding' in str(exc_info.value)
138+
139+
140+
def test_dag_cbor_decode_largest_unsigned_int() -> None:
141+
result = libipld.decode_dag_cbor(bytes.fromhex('1bffffffffffffffff'))
142+
assert result == 2**64 - 1
143+
144+
145+
def test_dag_cbor_decode_smallest_negative_int() -> None:
146+
result = libipld.decode_dag_cbor(bytes.fromhex('3bffffffffffffffff'))
147+
assert result == -(2**64)

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn decode_dag_cbor_to_pyobject<R: Read + Seek>(
122122
let major = decode::read_major(r)?;
123123
Ok(match major.kind() {
124124
MajorKind::UnsignedInt => decode::read_uint(r, major)?.into_pyobject(py)?.into(),
125-
MajorKind::NegativeInt => (-1 - decode::read_uint(r, major)? as i64).into_pyobject(py)?.into(),
125+
MajorKind::NegativeInt => (-1 - decode::read_uint(r, major)? as i128).into_pyobject(py)?.into(),
126126
MajorKind::ByteString => {
127127
let len = decode::read_uint(r, major)?;
128128
PyBytes::new(py, &decode::read_bytes(r, len)?).into_pyobject(py)?.into()

0 commit comments

Comments
 (0)