-
Notifications
You must be signed in to change notification settings - Fork 54
patch: crash for invalid context diff input #979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
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)
* 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
Pull Request Test Coverage Report for Build 13666636320Details
💛 - Coveralls |
|
edit: catch error when the patch has the line numbers reversed |
briandfoy
approved these changes
Mar 5, 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.