Skip to content

Commit d0c8123

Browse files
committed
reproduce failure when parsing malformed commit (#1438)
Note that Git can parse it. It's notable that it parses the name as `Gregor Hartmann` and the email as `gh <Gregor Hartmann<[email protected]`, while the author/commiter lines are `Gregor Hartmann<gh <Gregor Hartmann<[email protected]>>`
1 parent 36f221b commit d0c8123

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

gix-actor/src/signature/decode.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
pub(crate) mod function {
2+
use crate::{IdentityRef, SignatureRef};
23
use bstr::ByteSlice;
34
use gix_date::{time::Sign, OffsetInSeconds, SecondsSinceUnixEpoch, Time};
45
use gix_utils::btoi::to_signed;
6+
use winnow::error::{ErrMode, ErrorKind};
57
use winnow::{
68
combinator::{alt, separated_pair, terminated},
79
error::{AddContext, ParserError, StrContext},
@@ -10,8 +12,6 @@ pub(crate) mod function {
1012
token::{take, take_until, take_while},
1113
};
1214

13-
use crate::{IdentityRef, SignatureRef};
14-
1515
const SPACE: &[u8] = b" ";
1616

1717
/// Parse a signature from the bytes input `i` using `nom`.
@@ -64,6 +64,9 @@ pub(crate) mod function {
6464
pub fn identity<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>(
6565
i: &mut &'a [u8],
6666
) -> PResult<IdentityRef<'a>, E> {
67+
let eol = i
68+
.find_byte(b'\n')
69+
.ok_or(ErrMode::Cut(E::from_error_kind(i, ErrorKind::Eof)))?;
6770
(
6871
terminated(take_until(0.., &b" <"[..]), take(2usize)).context(StrContext::Expected("<name>".into())),
6972
terminated(take_until(0.., &b">"[..]), take(1usize)).context(StrContext::Expected("<email>".into())),

gix-object/tests/commit/from_bytes.rs

+26
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,32 @@ fn invalid_timestsamp() {
3535
);
3636
}
3737

38+
#[test]
39+
fn invalid_email_of_committer() {
40+
let actor = gix_actor::SignatureRef {
41+
name: b"Gregor Hartmann<gh".as_bstr(),
42+
email: b"Gregor Hartmann<[email protected]>".as_bstr(),
43+
time: Time {
44+
seconds: 1270814970,
45+
offset: 2 * 60 * 60,
46+
sign: Sign::Plus,
47+
},
48+
};
49+
assert_eq!(
50+
CommitRef::from_bytes(&fixture_name("commit", "invalid-actor.txt"))
51+
.expect("ignore strangely formed actor format"),
52+
CommitRef {
53+
tree: b"aee896327aa08c20f9ce80c9060aefe47edc65be".as_bstr(),
54+
parents: [b"d93091832789fc586916720da62a341a731fbd66".as_bstr()].into(),
55+
author: actor,
56+
committer: actor,
57+
encoding: None,
58+
message: b"add methods for tablecontrol".as_bstr(),
59+
extra_headers: vec![]
60+
}
61+
);
62+
}
63+
3864
#[test]
3965
fn unsigned() -> crate::Result {
4066
assert_eq!(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tree 220738fd4199e95a2b244465168366a73ebdf271
2+
parent 209fbe2d632761b30b7b17422914e11b93692833
3+
author Gregor Hartmann<gh <Gregor Hartmann<[email protected]>> 1282910542 +0200
4+
committer Gregor Hartmann<gh <Gregor Hartmann<[email protected]>> 1282910542 +0200
5+
6+
build breakers

0 commit comments

Comments
 (0)