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

Bug#175363: dpkg-gencontrol and controllib must set binmode



Package: dpkg-dev
Severity: important

Currently, dpkg-dev perl scripts like dpkg-gencontrol open files using
the default method.  In Perl 5.8, under UTF-8 locales like mine, this
will open them in UTF-8 mode.  Under ISO-8859-1 locales, Perl will
attempt to convert the data to UTF-8 internally.  When using non-ASCII
values like UTF-8, this will generally lead to corrputed data.  The
solution is to treat the streams as streams of bytes by setting
binmode() on them, so perl will do no conversion.  Probably an even
better solution is to just mandate that control files are UTF-8, but
we'll save that for later.  Attached is a patch.


--- controllib.pl~	2002-05-24 22:46:50.000000000 -0400
+++ controllib.pl	2003-01-04 18:57:31.000000000 -0500
@@ -105,6 +105,7 @@
     if (length($varlistfile) and $dosubstvars) {
         $varlistfile="./$varlistfile" if $varlistfile =~ m/\s/;
         if (open(SV,"< $varlistfile")) {
+	    binmode(SV);
             while (<SV>) {
                 next if m/^\#/ || !m/\S/;
                 s/\s*\n$//;
@@ -142,6 +143,7 @@
     $controlfile="./$controlfile" if $controlfile =~ m/^\s/;
 
     open(CDATA,"< $controlfile") || &error("cannot read control file $controlfile: $!");
+    binmode(CDATA);
     $indices= &parsecdata('C',1,"control file $controlfile");
     $indices >= 2 || &error("control file must have at least one binary package part");
 
@@ -154,6 +156,7 @@
 
 sub parsechangelog {
     defined($c=open(CDATA,"-|")) || &syserr("fork for parse changelog");
+    binmode (CDATA);
     if (!$c) {
         @al=($parsechangelog);
         push(@al,"-F$changelogformat") if length($changelogformat);
--- dpkg-gencontrol.pl~	2003-01-04 18:57:48.000000000 -0500
+++ dpkg-gencontrol.pl	2003-01-04 19:03:26.000000000 -0500
@@ -211,9 +211,11 @@
 
 $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
 open(Y,"> $fileslistfile.new") || &syserr("open new files list file");
+binmode(Y);
 chown(@fowner, "$fileslistfile.new") 
 		|| &syserr("chown new files list file");
 if (open(X,"< $fileslistfile")) {
+    binmode(X);
     while (<X>) {
         chomp;
         next if m/^([-+0-9a-z.]+)_[^_]+_(\w+)\.deb /
@@ -242,6 +244,7 @@
     $cf= "./$cf" if $cf =~ m/^\s/;
     open(STDOUT,"> $cf.new") ||
         &syserr("cannot open new output control file \`$cf.new'");
+    binmode(STDOUT);
 }
 &outputclose(1);
 if (!$stdout) {

Reply to: