Skip to content

Commit

Permalink
Fix crash with invalid length for base16 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Apr 8, 2023
1 parent 1265f22 commit 61637ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### Patch

- Fix crash with invalid length for base16

## 0.3.1

### Minor
Expand Down
3 changes: 1 addition & 2 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ where
let (next, olen) = match base.decode_mut(&input[0 .. next], &mut output[0 .. mlen]) {
Ok(olen) => (next, olen),
Err(mut partial) => {
if partial.error.kind != DecodeKind::Length {
if partial.error.kind != DecodeKind::Length || ilen == 0 {
partial.error.position += pos;
return Err(Error::Decode(partial.error));
}
assert_ne!(ilen, 0);
(partial.read, partial.written)
}
};
Expand Down
1 change: 1 addition & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ unit "-md -b64 -p= -g'$LF'" \
"Zg$LF$LF=$LF$LF=Z$LF${LF}m$LF${LF}8=${LF}Zg-=" 'ffo' 'invalid symbol at 19'
unit "-md -b64 -p= -g'$LF' --block=8" \
"Zg$LF$LF=$LF$LF=Z$LF${LF}m$LF${LF}8=${LF}Zg-=" ffo 'invalid symbol at 19'
unit '-md -b16 -gx' 6474y dt 'invalid length at 4'
echo
echo -n 'symbol:'
unit '-md -b64 -p=' Zg==Zm8=Zg-= '' 'invalid symbol at 10'
Expand Down

0 comments on commit 61637ba

Please sign in to comment.