33a815d107
If one line in a file has length (including newline) of 2^31, then applying sed -i to that file truncates it to size 0. I first noticed it like this: Create a file with line of length 2^31-1 $ perl -le 'print "v"x(2**31-1)' > k Then prepend a byte to that line: $ sed -i 's/^/v/' k Surprise! The file is empty. * sed/utils.c (ck_getline): Declare "result" to be of type ssize_t, rather than int, to match the return type of getline. Upstream 81ce070727b225a1e23e5a48f775811c8a9e7366 by Jim Meyering <meyering@redhat.com>
59 lines
1.7 KiB
Diff
59 lines
1.7 KiB
Diff
From 695e76c32320a6cf641bc91c077ded01c6da0315 Mon Sep 17 00:00:00 2001
|
|
From: "Vojtech Vitek (V-Teq)" <vvitek@redhat.com>
|
|
Date: Tue, 12 Jul 2011 15:37:12 +0200
|
|
Subject: [PATCH] avoid silent data loss when an input line is 2^31 bytes or
|
|
longer
|
|
|
|
If one line in a file has length (including newline) of 2^31, then
|
|
applying sed -i to that file truncates it to size 0. I first
|
|
noticed it like this: Create a file with line of length 2^31-1
|
|
$ perl -le 'print "v"x(2**31-1)' > k
|
|
Then prepend a byte to that line:
|
|
$ sed -i 's/^/v/' k
|
|
Surprise! The file is empty.
|
|
* sed/utils.c (ck_getline): Declare "result" to be of type ssize_t,
|
|
rather than int, to match the return type of getline.
|
|
|
|
Upstream 81ce070727b225a1e23e5a48f775811c8a9e7366
|
|
by Jim Meyering <meyering@redhat.com>
|
|
---
|
|
NEWS | 4 ++++
|
|
sed/utils.c | 4 ++--
|
|
2 files changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/NEWS b/NEWS
|
|
index cd755d2..91d7c15 100644
|
|
--- a/NEWS
|
|
+++ b/NEWS
|
|
@@ -1,3 +1,7 @@
|
|
+Patches from Sed 4.2.2
|
|
+
|
|
+* don't misbehave (truncate input) for lines of length 2^31 and longer
|
|
+
|
|
Sed 4.2.1
|
|
|
|
* fix parsing of s/[[[[[[[[[]//
|
|
diff --git a/sed/utils.c b/sed/utils.c
|
|
index 82b53a6..c416d59 100644
|
|
--- a/sed/utils.c
|
|
+++ b/sed/utils.c
|
|
@@ -1,5 +1,5 @@
|
|
/* Functions from hack's utils library.
|
|
- Copyright (C) 1989, 1990, 1991, 1998, 1999, 2003, 2008, 2009
|
|
+ Copyright (C) 1989, 1990, 1991, 1998, 1999, 2003, 2008, 2009, 2011
|
|
Free Software Foundation, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
@@ -269,7 +269,7 @@ ck_getline(text, buflen, stream)
|
|
size_t *buflen;
|
|
FILE *stream;
|
|
{
|
|
- int result;
|
|
+ ssize_t result;
|
|
if (!ferror (stream))
|
|
result = getline (text, buflen, stream);
|
|
|
|
--
|
|
1.7.5.4
|
|
|