bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gzip > 1.3.? broken on NSK


From: Paul Eggert
Subject: Re: gzip > 1.3.? broken on NSK
Date: Mon, 11 Dec 2006 11:00:46 -0800
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

"Matthew Woehlke" <address@hidden> writes:

>> I installed the following; this should fix all the NSK bugs you
>> reported. Can you please try it?
>> [patch snipped]
>
> Hmm, either that didn't work, or didn't make it into 1.3.8;

It's in 1.3.8.  So it must not have worked.

Can you please try this patch to gzip 1.3.8?  It's more elaborate, but
more conservative.  It shouldn't change the behavior unless SSIZE_MAX
< 64 KiB.

I have installed this into CVS.  I'd like to get a stable version out
the door soon, so if you can try it now then you'll know that the
stable version works on NSK.

Thanks.

2006-12-11  Paul Eggert  <address@hidden>

        The SSIZE_MAX fix didn't work on NSK, so fix it in a more-reliable
        (albeit more-complicated) way.  Problem reported by Matthew Woehlke.
        * gzip.h (read_buffer): New decl.
        * unlzw.c (unlzw): Use read_buffer rather than read.
        * zip.c (file_read): Likewise.
        * util.c (copy, fill_inbuf): Likewise.
        (read_buffer, write_buffer): New functions.
        (write_buf): Use write_buffer rather than write.

        Undo the previous SSIZE_MAX-related change; it didn't work.
        * gzip.c: Include <limits.h>.
        * util.c: Likewise.
        * gzip.h: Don't include <limits.h>.
        (INBUFSIZ): Don't worry about SSIZE_MAX here.

Index: gzip.c
===================================================================
RCS file: /cvsroot/gzip/gzip/gzip.c,v
retrieving revision 1.9
diff -p -u -r1.9 gzip.c
--- gzip.c      9 Dec 2006 01:19:52 -0000       1.9
+++ gzip.c      11 Dec 2006 18:53:59 -0000
@@ -85,6 +85,10 @@ static char rcsid[] = "$Id: gzip.c,v 1.9
 #  include <fcntl.h>
 #endif
 
+#ifdef HAVE_LIMITS_H
+#  include <limits.h>
+#endif
+
 #ifdef HAVE_UNISTD_H
 #  include <unistd.h>
 #endif
Index: gzip.h
===================================================================
RCS file: /cvsroot/gzip/gzip/gzip.h,v
retrieving revision 1.5
diff -p -u -r1.5 gzip.h
--- gzip.h      9 Dec 2006 01:19:52 -0000       1.5
+++ gzip.h      11 Dec 2006 18:53:59 -0000
@@ -59,10 +59,6 @@
 #  define memzero(s, n)     bzero((s), (n))
 #endif
 
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
-
 #ifndef RETSIGTYPE
 #  define RETSIGTYPE void
 #endif
@@ -105,10 +101,6 @@ extern int method;         /* compressio
 #  else
 #    define INBUFSIZ  0x8000  /* input buffer size */
 #  endif
-#  if defined SSIZE_MAX && SSIZE_MAX < INBUFSIZ
-#    undef INBUFSIZ
-#    define INBUFSIZ SSIZE_MAX
-#  endif
 #endif
 #define INBUF_EXTRA  64     /* required by unlzw() */
 
@@ -329,6 +321,7 @@ extern int  fill_inbuf    OF((int eof_ok
 extern void flush_outbuf  OF((void));
 extern void flush_window  OF((void));
 extern void write_buf     OF((int fd, voidp buf, unsigned cnt));
+extern int read_buffer    OF((int fd, voidp buf, unsigned int cnt));
 extern char *strlwr       OF((char *s));
 extern char *gzip_base_name OF((char *fname));
 extern int xunlink        OF((char *fname));
Index: unlzw.c
===================================================================
RCS file: /cvsroot/gzip/gzip/unlzw.c,v
retrieving revision 1.4
diff -p -u -r1.4 unlzw.c
--- unlzw.c     20 Nov 2006 08:40:34 -0000      1.4
+++ unlzw.c     11 Dec 2006 18:53:59 -0000
@@ -257,7 +257,8 @@ int unlzw(in, out)
        posbits = 0;
 
        if (insize < INBUF_EXTRA) {
-           if ((rsize = read(in, (char*)inbuf+insize, INBUFSIZ)) == -1) {
+           rsize = read_buffer (in, (char *) inbuf + insize, INBUFSIZ);
+           if (rsize == -1) {
                read_error();
            }
            insize += rsize;
Index: util.c
===================================================================
RCS file: /cvsroot/gzip/gzip/util.c,v
retrieving revision 1.5
diff -p -u -r1.5 util.c
--- util.c      9 Dec 2006 01:19:53 -0000       1.5
+++ util.c      11 Dec 2006 18:53:59 -0000
@@ -28,6 +28,9 @@ static char rcsid[] = "$Id: util.c,v 1.5
 
 #include "tailor.h"
 
+#ifdef HAVE_LIMITS_H
+#  include <limits.h>
+#endif
 #ifdef HAVE_UNISTD_H
 #  include <unistd.h>
 #endif
@@ -49,6 +52,8 @@ static char rcsid[] = "$Id: util.c,v 1.5
 #  define CHAR_BIT 8
 #endif
 
+static int write_buffer OF((int, voidp, unsigned int));
+
 extern ulg crc_32_tab[];   /* crc table, defined below */
 
 /* ===========================================================================
@@ -62,7 +67,7 @@ int copy(in, out)
     while (insize != 0 && (int)insize != -1) {
        write_buf(out, (char*)inbuf, insize);
        bytes_out += insize;
-       insize = read(in, (char*)inbuf, INBUFSIZ);
+       insize = read_buffer (in, (char *) inbuf, INBUFSIZ);
     }
     if ((int)insize == -1) {
        read_error();
@@ -117,7 +122,7 @@ int fill_inbuf(eof_ok)
     /* Read as much as possible */
     insize = 0;
     do {
-       len = read(ifd, (char*)inbuf+insize, INBUFSIZ-insize);
+       len = read_buffer (ifd, (char *) inbuf + insize, INBUFSIZ - insize);
        if (len == 0) break;
        if (len == -1) {
          read_error();
@@ -137,6 +142,35 @@ int fill_inbuf(eof_ok)
     return inbuf[0];
 }
 
+/* Like the standard read function, except do not attempt to read more
+   than SSIZE_MAX bytes at a time.  */
+int
+read_buffer (fd, buf, cnt)
+     int fd;
+     voidp buf;
+     unsigned int cnt;
+{
+#ifdef SSIZE_MAX
+  if (SSIZE_MAX < cnt)
+    cnt = SSIZE_MAX;
+#endif
+  return read (fd, buf, cnt);
+}
+
+/* Likewise for 'write'.  */
+static int
+write_buffer (fd, buf, cnt)
+     int fd;
+     voidp buf;
+     unsigned int cnt;
+{
+#ifdef SSIZE_MAX
+  if (SSIZE_MAX < cnt)
+    cnt = SSIZE_MAX;
+#endif
+  return write (fd, buf, cnt);
+}
+
 /* ===========================================================================
  * Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
  * (used for the compressed data only)
@@ -177,7 +211,7 @@ void write_buf(fd, buf, cnt)
 {
     unsigned  n;
 
-    while ((n = write(fd, buf, cnt)) != cnt) {
+    while ((n = write_buffer (fd, buf, cnt)) != cnt) {
        if (n == (unsigned)(-1)) {
            write_error();
        }
Index: zip.c
===================================================================
RCS file: /cvsroot/gzip/gzip/zip.c,v
retrieving revision 1.5
diff -p -u -r1.5 zip.c
--- zip.c       9 Dec 2006 01:19:53 -0000       1.5
+++ zip.c       11 Dec 2006 18:53:59 -0000
@@ -126,7 +126,7 @@ int file_read(buf, size)
 
     Assert(insize == 0, "inbuf not empty");
 
-    len = read(ifd, buf, size);
+    len = read_buffer (ifd, buf, size);
     if (len == 0) return (int)len;
     if (len == (unsigned)-1) {
        read_error();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]