@@ -222,12 +222,47 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
222222 return retval ;
223223}
224224
225+ static int fsck_ident (char * * ident , struct object * obj , fsck_error error_func )
226+ {
227+ if (* * ident == '<' || * * ident == '\n' )
228+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - missing space before email" );
229+ * ident += strcspn (* ident , "<\n" );
230+ if ((* ident )[-1 ] != ' ' )
231+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - missing space before email" );
232+ if (* * ident != '<' )
233+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - missing email" );
234+ (* ident )++ ;
235+ * ident += strcspn (* ident , "<>\n" );
236+ if (* * ident != '>' )
237+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - bad email" );
238+ (* ident )++ ;
239+ if (* * ident != ' ' )
240+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - missing space before date" );
241+ (* ident )++ ;
242+ if (* * ident == '0' && (* ident )[1 ] != ' ' )
243+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - zero-padded date" );
244+ * ident += strspn (* ident , "0123456789" );
245+ if (* * ident != ' ' )
246+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - bad date" );
247+ (* ident )++ ;
248+ if ((* * ident != '+' && * * ident != '-' ) ||
249+ !isdigit ((* ident )[1 ]) ||
250+ !isdigit ((* ident )[2 ]) ||
251+ !isdigit ((* ident )[3 ]) ||
252+ !isdigit ((* ident )[4 ]) ||
253+ ((* ident )[5 ] != '\n' ))
254+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - bad time zone" );
255+ (* ident ) += 6 ;
256+ return 0 ;
257+ }
258+
225259static int fsck_commit (struct commit * commit , fsck_error error_func )
226260{
227261 char * buffer = commit -> buffer ;
228262 unsigned char tree_sha1 [20 ], sha1 [20 ];
229263 struct commit_graft * graft ;
230264 int parents = 0 ;
265+ int err ;
231266
232267 if (commit -> date == ULONG_MAX )
233268 return error_func (& commit -> object , FSCK_ERROR , "invalid author/committer line" );
@@ -266,6 +301,18 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
266301 }
267302 if (memcmp (buffer , "author " , 7 ))
268303 return error_func (& commit -> object , FSCK_ERROR , "invalid format - expected 'author' line" );
304+ buffer += 7 ;
305+ err = fsck_ident (& buffer , & commit -> object , error_func );
306+ if (err )
307+ return err ;
308+ if (memcmp (buffer , "committer " , strlen ("committer " )))
309+ return error_func (& commit -> object , FSCK_ERROR , "invalid format - expected 'committer' line" );
310+ buffer += strlen ("committer " );
311+ err = fsck_ident (& buffer , & commit -> object , error_func );
312+ if (err )
313+ return err ;
314+ if (* buffer != '\n' )
315+ return error_func (& commit -> object , FSCK_ERROR , "invalid format - expected blank line" );
269316 if (!commit -> tree )
270317 return error_func (& commit -> object , FSCK_ERROR , "could not load commit's tree %s" , sha1_to_hex (tree_sha1 ));
271318
0 commit comments