Skip to content

Commit c64efe6

Browse files
committed
Allow 0 input for the decode sizer (invalid otherwise)
1 parent 7bcfde5 commit c64efe6

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "darkbio-cobs"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
authors = ["Péter Szilágyi <peter@dark.bio>"]
55
description = "Fast COBS encoder and decoder"
66
repository = "https://github.com/dark-bio/cobs-rs"

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ pub const fn encode_buffer(size: usize) -> usize {
3030
}
3131

3232
/// Computes the maximum size needed to COBS decode a blind input data.
33-
///
34-
/// Note, 0 is not a valid CODE data size and the method will panic.
3533
#[inline]
3634
pub const fn decode_buffer(size: usize) -> usize {
3735
if size == 0 {
38-
panic!("size cannot be zero");
36+
// Zero length COBS is invalid. We could panic here, but that makes call
37+
// sites brittle when parsing potentially malicious input. We could also
38+
// return an error, but that makes the method so much uglier. Returning
39+
// zero is safe however, because the caller can still alloc a zero-byte
40+
// buffer and the decoder will error anyway.
41+
return 0;
3942
}
4043
size - 1
4144
}

0 commit comments

Comments
 (0)