@@ -74,8 +74,8 @@ static int parse_advance_expected(
74
74
return 0 ;
75
75
}
76
76
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))
79
79
80
80
static int parse_advance_ws (git_patch_parse_ctx * ctx )
81
81
{
@@ -220,7 +220,7 @@ static int parse_header_git_index(
220
220
{
221
221
if (parse_header_oid (& patch -> base .delta -> old_file .id ,
222
222
& patch -> base .delta -> old_file .id_abbrev , ctx ) < 0 ||
223
- parse_advance_expected_s (ctx , ".." ) < 0 ||
223
+ parse_advance_expected_str (ctx , ".." ) < 0 ||
224
224
parse_header_oid (& patch -> base .delta -> new_file .id ,
225
225
& patch -> base .delta -> new_file .id_abbrev , ctx ) < 0 )
226
226
return -1 ;
@@ -336,7 +336,7 @@ static int parse_header_percent(uint16_t *out, git_patch_parse_ctx *ctx)
336
336
337
337
parse_advance_chars (ctx , (end - ctx -> line ));
338
338
339
- if (parse_advance_expected_s (ctx , "%" ) < 0 )
339
+ if (parse_advance_expected_str (ctx , "%" ) < 0 )
340
340
return -1 ;
341
341
342
342
if (val > 100 )
@@ -379,6 +379,7 @@ static const header_git_op header_git_ops[] = {
379
379
{ "diff --git " , NULL },
380
380
{ "@@ -" , NULL },
381
381
{ "GIT binary patch" , NULL },
382
+ { "Binary files " , NULL },
382
383
{ "--- " , parse_header_git_oldpath },
383
384
{ "+++ " , parse_header_git_newpath },
384
385
{ "index " , parse_header_git_index },
@@ -404,7 +405,7 @@ static int parse_header_git(
404
405
int error = 0 ;
405
406
406
407
/* 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 )
408
409
return parse_err ("corrupt git diff header at line %d" , ctx -> line_num );
409
410
410
411
if (parse_header_path (& patch -> header_old_path , ctx ) < 0 )
@@ -443,7 +444,7 @@ static int parse_header_git(
443
444
goto done ;
444
445
445
446
parse_advance_ws (ctx );
446
- parse_advance_expected_s (ctx , "\n" );
447
+ parse_advance_expected_str (ctx , "\n" );
447
448
448
449
if (ctx -> line_len > 0 ) {
449
450
error = parse_err ("trailing data at line %d" , ctx -> line_num );
@@ -505,27 +506,27 @@ static int parse_hunk_header(
505
506
hunk -> hunk .old_lines = 1 ;
506
507
hunk -> hunk .new_lines = 1 ;
507
508
508
- if (parse_advance_expected_s (ctx , "@@ -" ) < 0 ||
509
+ if (parse_advance_expected_str (ctx , "@@ -" ) < 0 ||
509
510
parse_int (& hunk -> hunk .old_start , ctx ) < 0 )
510
511
goto fail ;
511
512
512
513
if (ctx -> line_len > 0 && ctx -> line [0 ] == ',' ) {
513
- if (parse_advance_expected_s (ctx , "," ) < 0 ||
514
+ if (parse_advance_expected_str (ctx , "," ) < 0 ||
514
515
parse_int (& hunk -> hunk .old_lines , ctx ) < 0 )
515
516
goto fail ;
516
517
}
517
518
518
- if (parse_advance_expected_s (ctx , " +" ) < 0 ||
519
+ if (parse_advance_expected_str (ctx , " +" ) < 0 ||
519
520
parse_int (& hunk -> hunk .new_start , ctx ) < 0 )
520
521
goto fail ;
521
522
522
523
if (ctx -> line_len > 0 && ctx -> line [0 ] == ',' ) {
523
- if (parse_advance_expected_s (ctx , "," ) < 0 ||
524
+ if (parse_advance_expected_str (ctx , "," ) < 0 ||
524
525
parse_int (& hunk -> hunk .new_lines , ctx ) < 0 )
525
526
goto fail ;
526
527
}
527
528
528
- if (parse_advance_expected_s (ctx , " @@" ) < 0 )
529
+ if (parse_advance_expected_str (ctx , " @@" ) < 0 )
529
530
goto fail ;
530
531
531
532
parse_advance_line (ctx );
@@ -782,7 +783,7 @@ static int parse_patch_binary(
782
783
{
783
784
int error ;
784
785
785
- if (parse_advance_expected_s (ctx , "GIT binary patch" ) < 0 ||
786
+ if (parse_advance_expected_str (ctx , "GIT binary patch" ) < 0 ||
786
787
parse_advance_nl (ctx ) < 0 )
787
788
return parse_err ("corrupt git binary header at line %d" , ctx -> line_num );
788
789
@@ -804,6 +805,24 @@ static int parse_patch_binary(
804
805
return parse_err ("corrupt git binary patch separator at line %d" ,
805
806
ctx -> line_num );
806
807
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 ;
807
826
patch -> base .delta -> flags |= GIT_DIFF_FLAG_BINARY ;
808
827
return 0 ;
809
828
}
@@ -840,6 +859,8 @@ static int parse_patch_body(
840
859
{
841
860
if (parse_ctx_contains_s (ctx , "GIT binary patch" ))
842
861
return parse_patch_binary (patch , ctx );
862
+ else if (parse_ctx_contains_s (ctx , "Binary files " ))
863
+ return parse_patch_binary_nodata (patch , ctx );
843
864
else
844
865
return parse_patch_hunks (patch , ctx );
845
866
}
0 commit comments