@@ -74,8 +74,8 @@ static int parse_advance_expected(
7474 return 0 ;
7575}
7676
77- #define parse_advance_expected_s (ctx , str ) \
78- parse_advance_expected(ctx, str, sizeof (str) - 1 )
77+ #define parse_advance_expected_str (ctx , str ) \
78+ parse_advance_expected(ctx, str, strlen (str))
7979
8080static int parse_advance_ws (git_patch_parse_ctx * ctx )
8181{
@@ -220,7 +220,7 @@ static int parse_header_git_index(
220220{
221221 if (parse_header_oid (& patch -> base .delta -> old_file .id ,
222222 & patch -> base .delta -> old_file .id_abbrev , ctx ) < 0 ||
223- parse_advance_expected_s (ctx , ".." ) < 0 ||
223+ parse_advance_expected_str (ctx , ".." ) < 0 ||
224224 parse_header_oid (& patch -> base .delta -> new_file .id ,
225225 & patch -> base .delta -> new_file .id_abbrev , ctx ) < 0 )
226226 return -1 ;
@@ -336,7 +336,7 @@ static int parse_header_percent(uint16_t *out, git_patch_parse_ctx *ctx)
336336
337337 parse_advance_chars (ctx , (end - ctx -> line ));
338338
339- if (parse_advance_expected_s (ctx , "%" ) < 0 )
339+ if (parse_advance_expected_str (ctx , "%" ) < 0 )
340340 return -1 ;
341341
342342 if (val > 100 )
@@ -379,6 +379,7 @@ static const header_git_op header_git_ops[] = {
379379 { "diff --git " , NULL },
380380 { "@@ -" , NULL },
381381 { "GIT binary patch" , NULL },
382+ { "Binary files " , NULL },
382383 { "--- " , parse_header_git_oldpath },
383384 { "+++ " , parse_header_git_newpath },
384385 { "index " , parse_header_git_index },
@@ -404,7 +405,7 @@ static int parse_header_git(
404405 int error = 0 ;
405406
406407 /* Parse the diff --git line */
407- if (parse_advance_expected_s (ctx , "diff --git " ) < 0 )
408+ if (parse_advance_expected_str (ctx , "diff --git " ) < 0 )
408409 return parse_err ("corrupt git diff header at line %d" , ctx -> line_num );
409410
410411 if (parse_header_path (& patch -> header_old_path , ctx ) < 0 )
@@ -443,7 +444,7 @@ static int parse_header_git(
443444 goto done ;
444445
445446 parse_advance_ws (ctx );
446- parse_advance_expected_s (ctx , "\n" );
447+ parse_advance_expected_str (ctx , "\n" );
447448
448449 if (ctx -> line_len > 0 ) {
449450 error = parse_err ("trailing data at line %d" , ctx -> line_num );
@@ -505,27 +506,27 @@ static int parse_hunk_header(
505506 hunk -> hunk .old_lines = 1 ;
506507 hunk -> hunk .new_lines = 1 ;
507508
508- if (parse_advance_expected_s (ctx , "@@ -" ) < 0 ||
509+ if (parse_advance_expected_str (ctx , "@@ -" ) < 0 ||
509510 parse_int (& hunk -> hunk .old_start , ctx ) < 0 )
510511 goto fail ;
511512
512513 if (ctx -> line_len > 0 && ctx -> line [0 ] == ',' ) {
513- if (parse_advance_expected_s (ctx , "," ) < 0 ||
514+ if (parse_advance_expected_str (ctx , "," ) < 0 ||
514515 parse_int (& hunk -> hunk .old_lines , ctx ) < 0 )
515516 goto fail ;
516517 }
517518
518- if (parse_advance_expected_s (ctx , " +" ) < 0 ||
519+ if (parse_advance_expected_str (ctx , " +" ) < 0 ||
519520 parse_int (& hunk -> hunk .new_start , ctx ) < 0 )
520521 goto fail ;
521522
522523 if (ctx -> line_len > 0 && ctx -> line [0 ] == ',' ) {
523- if (parse_advance_expected_s (ctx , "," ) < 0 ||
524+ if (parse_advance_expected_str (ctx , "," ) < 0 ||
524525 parse_int (& hunk -> hunk .new_lines , ctx ) < 0 )
525526 goto fail ;
526527 }
527528
528- if (parse_advance_expected_s (ctx , " @@" ) < 0 )
529+ if (parse_advance_expected_str (ctx , " @@" ) < 0 )
529530 goto fail ;
530531
531532 parse_advance_line (ctx );
@@ -782,7 +783,7 @@ static int parse_patch_binary(
782783{
783784 int error ;
784785
785- if (parse_advance_expected_s (ctx , "GIT binary patch" ) < 0 ||
786+ if (parse_advance_expected_str (ctx , "GIT binary patch" ) < 0 ||
786787 parse_advance_nl (ctx ) < 0 )
787788 return parse_err ("corrupt git binary header at line %d" , ctx -> line_num );
788789
@@ -804,6 +805,24 @@ static int parse_patch_binary(
804805 return parse_err ("corrupt git binary patch separator at line %d" ,
805806 ctx -> line_num );
806807
808+ patch -> base .binary .contains_data = 1 ;
809+ patch -> base .delta -> flags |= GIT_DIFF_FLAG_BINARY ;
810+ return 0 ;
811+ }
812+
813+ static int parse_patch_binary_nodata (
814+ git_patch_parsed * patch ,
815+ git_patch_parse_ctx * ctx )
816+ {
817+ if (parse_advance_expected_str (ctx , "Binary files " ) < 0 ||
818+ parse_advance_expected_str (ctx , patch -> header_old_path ) < 0 ||
819+ parse_advance_expected_str (ctx , " and " ) < 0 ||
820+ parse_advance_expected_str (ctx , patch -> header_new_path ) < 0 ||
821+ parse_advance_expected_str (ctx , " differ" ) < 0 ||
822+ parse_advance_nl (ctx ) < 0 )
823+ return parse_err ("corrupt git binary header at line %d" , ctx -> line_num );
824+
825+ patch -> base .binary .contains_data = 0 ;
807826 patch -> base .delta -> flags |= GIT_DIFF_FLAG_BINARY ;
808827 return 0 ;
809828}
@@ -840,6 +859,8 @@ static int parse_patch_body(
840859{
841860 if (parse_ctx_contains_s (ctx , "GIT binary patch" ))
842861 return parse_patch_binary (patch , ctx );
862+ else if (parse_ctx_contains_s (ctx , "Binary files " ))
863+ return parse_patch_binary_nodata (patch , ctx );
843864 else
844865 return parse_patch_hunks (patch , ctx );
845866}
0 commit comments