Package: cpio-win32
Severity: normal
Tags: patch

Output is corrupted when input contains newlines, because write() without
binary mode replaces all \n with \r\n (even where \r is already present!),
resulting in checksum failure.

Attached patch fixes the problem.  I've also sent it upstream.

-- System Information:
Debian Release: lenny/sid
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-5-amd64
Locale: LANG=ca_AD.UTF-8, LC_CTYPE=ca_AD.UTF-8 (charmap=UTF-8)
diff -ur cpio-2.9.old/lib/fcntl_.h cpio-2.9/lib/fcntl_.h
--- cpio-2.9.old/lib/fcntl_.h	2007-06-28 19:18:55.000000000 +0200
+++ cpio-2.9/lib/fcntl_.h	2008-02-05 17:00:24.000000000 +0100
@@ -111,7 +111,10 @@
 # undef O_TEXT
 #endif
 
-#ifndef O_BINARY
+#ifdef O_BINARY
+# define SET_BINARY_MODE(arc) setmode(arc, O_BINARY)
+#else
+# define SET_BINARY_MODE(arc)
 # define O_BINARY 0
 # define O_TEXT 0
 #endif
diff -ur cpio-2.9.old/lib/system.h cpio-2.9/lib/system.h
--- cpio-2.9.old/lib/system.h	2008-02-05 14:03:34.000000000 +0100
+++ cpio-2.9/lib/system.h	2008-02-05 17:00:37.000000000 +0100
@@ -109,9 +109,6 @@
 # define O_TRUNC	32	/* truncate file on open */
 #endif
 
-#ifndef O_BINARY
-# define O_BINARY 0
-#endif
 #ifndef O_DIRECTORY
 # define O_DIRECTORY 0
 #endif
@@ -490,13 +487,11 @@
 #endif
 
 #if MSDOS
-# define SET_BINARY_MODE(arc) setmode(arc, O_BINARY)
 # define ERRNO_IS_EACCES errno == EACCES
 # define mkdir(file, mode) (mkdir) (file)
 # define TTY_NAME "con"
 # define sys_reset_uid_gid()
 #else
-# define SET_BINARY_MODE(arc)
 # define ERRNO_IS_EACCES 0
 # define TTY_NAME "/dev/tty"
 # define sys_reset_uid_gid() \
diff -ur cpio-2.9.old/src/main.c cpio-2.9/src/main.c
--- cpio-2.9.old/src/main.c	2007-06-28 12:46:41.000000000 +0200
+++ cpio-2.9/src/main.c	2008-02-05 17:03:48.000000000 +0100
@@ -792,6 +792,8 @@
   
   initialize_buffers ();
 
+  SET_BINARY_MODE (1);
+
   (*copy_function) ();
 
   if (archive_des >= 0 && rmtclose (archive_des) == -1)

Reply via email to