I ran into a segfault with patch(1) in a port, here's a test case with a minimal reproducer.
$ echo foo > test $ perl -e 'print "--- test.orig\n+++ test\n@@ -1,1 +1,2 @@\n foo\n+" . 'x' x 32768 . "\n\\ No newline at end of file\n"' > test.patch $ patch < test.patch Hmm... Looks like a unified diff to me... The text leading up to this was: -------------------------- |--- test.orig |+++ test -------------------------- Patching file test using Plan A... Segmentation fault (core dumped) $ egdb -q /usr/src/usr.bin/patch/obj/patch patch.core Reading symbols from /usr/src/usr.bin/patch/obj/patch... [New process 276205] Core was generated by `patch'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00000f18920a76e0 in another_hunk () at /usr/src/usr.bin/patch/pch.c:1008 1008 s[p_len[filldst - 1]] = 0; (gdb) list 1003 p_line[filldst] = s; 1004 p_len[filldst++] = strlen(s); 1005 if (fillsrc > p_ptrn_lines) { 1006 if (remove_special_line()) { 1007 p_len[filldst - 1] -= 1; 1008 s[p_len[filldst - 1]] = 0; 1009 } 1010 } 1011 break; 1012 default: (gdb) quit $