Skip to content

Conversation

@mknos
Copy link
Contributor

@mknos mknos commented Mar 5, 2025

  • I generated a Context diff with 2 hunks
  • I manually swapped the 2 numbers at the top of hunk1, from "1,4" to "4,1" (the line number range for the hunk)
  • GNU patch correctly rejected the invalid diff, but this version crashed with an ARRAY error
  • Add validation to reject a backwards range (based on code previously added for Normal diffs)
%cat diff.ctx 
*** id	Wed Mar  5 09:16:33 2025
--- id2	Wed Mar  5 09:14:36 2025
***************
*** 4,1 ****
- #!/usr/bin/perl
  
  =begin metadata
  
--- 1,3 ----
***************
*** 12,24 ****
  =cut
  
  
- #
- # An implementation of the 'id' utility in Perl.  Written for the Perl Power
- # Tools (PPT) project by Theo Van Dinter (felicity@kluge.net).
- #
- # $Id: id,v 1.2 2004/08/05 14:17:43 cwest Exp $
- # - 
  use strict;
  
  use File::Basename qw(basename); --- 11,16 ----
%perl -Mwarnings -Mdiagnostics  patch -c id diff.ctx
Hmm...  Looks like a context diff to me...
Patching file id using Plan A...
Short hunk ignored...no second line range.
1 out of 1 hunks ignored--saving rejects to id.rej

Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh>
	line 249 (#1)
    (F) A value used as either a hard reference or a symbolic reference must
    be a defined value.  This helps to delurk some insidious errors.
    
Uncaught exception from user code:
	Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh> line 249.
	Patch::bless(Patch::Context=HASH(0x55908a4f50)) called at patch line 161

* I generated a Context diff with 2 hunks
* I manually swapped the 2 numbers at the top of hunk1, from "1,4" to "4,1" (the line number range for the hunk)
* GNU patch correctly rejected this invalid diff, but this version crashed with an ARRAY error
* Add validation for backwards range, based on code previously added for Normal diffs

%cat diff.ctx 
*** id	Wed Mar  5 09:16:33 2025
--- id2	Wed Mar  5 09:14:36 2025
***************
*** 4,1 ****
- #!/usr/bin/perl
  
  =begin metadata
  
--- 1,3 ----
***************
*** 12,24 ****
  =cut
  
  
- #
- # An implementation of the 'id' utility in Perl.  Written for the Perl Power
- # Tools (PPT) project by Theo Van Dinter (felicity@kluge.net).
- #
- # $Id: id,v 1.2 2004/08/05 14:17:43 cwest Exp $
- #
- 
  use strict;
  
  use File::Basename qw(basename);
--- 11,16 ----

%perl -Mwarnings -Mdiagnostics  patch -c id diff.ctx
Hmm...  Looks like a context diff to me...
Patching file id using Plan A...
Short hunk ignored...no second line range.
1 out of 1 hunks ignored--saving rejects to id.rej

Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh>
	line 249 (briandfoy#1)
    (F) A value used as either a hard reference or a symbolic reference must
    be a defined value.  This helps to delurk some insidious errors.
    
Uncaught exception from user code:
	Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh> line 249.
	Patch::bless(Patch::Context=HASH(0x55908a4f50)) called at patch line 161
@mknos mknos temporarily deployed to housekeeping March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos had a problem deploying to automated_testing March 5, 2025 01:41 — with GitHub Actions Error
@mknos mknos had a problem deploying to automated_testing March 5, 2025 01:41 — with GitHub Actions Failure
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing March 5, 2025 01:41 — with GitHub Actions Inactive
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: patch The patch program Status: needs verification issue needs to be verified Type: bug an existing feature does not work labels Mar 5, 2025
@github-actions github-actions bot requested a review from briandfoy March 5, 2025 01:41
@coveralls
Copy link

coveralls commented Mar 5, 2025

Pull Request Test Coverage Report for Build 13666636320

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.9%) to 70.088%

Totals Coverage Status
Change from base Build 13656102414: -0.9%
Covered Lines: 396
Relevant Lines: 565

💛 - Coveralls

@briandfoy briandfoy self-assigned this Mar 5, 2025
@briandfoy
Copy link
Owner

edit: catch error when the patch has the line numbers reversed

@briandfoy briandfoy merged commit fa977b3 into briandfoy:master Mar 5, 2025
21 of 24 checks passed
@github-actions github-actions bot added Status: accepted The fix is accepted and removed Status: needs verification issue needs to be verified Priority: low get to this whenever labels Mar 5, 2025
@briandfoy briandfoy added Status: released there is a new release with this fix and removed Status: accepted The fix is accepted labels Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Program: patch The patch program Status: released there is a new release with this fix Type: bug an existing feature does not work Type: enhancement improve a feature that already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants