Skip to content

Commit 92d4148

Browse files
authored
fix: off by 1 error in Method::from_bytes causing an allocation (#708)
1 parent 5a1a5e8 commit 92d4148

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/method.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Method {
123123
_ => Method::extension_inline(src),
124124
},
125125
_ => {
126-
if src.len() < InlineExtension::MAX {
126+
if src.len() <= InlineExtension::MAX {
127127
Method::extension_inline(src)
128128
} else {
129129
let allocated = AllocatedExtension::new(src)?;
@@ -465,6 +465,21 @@ mod test {
465465

466466
let long_method = "This_is_a_very_long_method.It_is_valid_but_unlikely.";
467467
assert_eq!(Method::from_str(long_method).unwrap(), long_method);
468+
469+
let longest_inline_method = [b'A'; InlineExtension::MAX];
470+
assert_eq!(
471+
Method::from_bytes(&longest_inline_method).unwrap(),
472+
Method(ExtensionInline(
473+
InlineExtension::new(&longest_inline_method).unwrap()
474+
))
475+
);
476+
let shortest_allocated_method = [b'A'; InlineExtension::MAX + 1];
477+
assert_eq!(
478+
Method::from_bytes(&shortest_allocated_method).unwrap(),
479+
Method(ExtensionAllocated(
480+
AllocatedExtension::new(&shortest_allocated_method).unwrap()
481+
))
482+
);
468483
}
469484

470485
#[test]

0 commit comments

Comments
 (0)