Skip Menu |

This queue is for tickets about the Archive-Ar CPAN distribution.

Report information
The Basics
Id: 18383
Status: resolved
Priority: 0/
Queue: Archive-Ar

People
Owner: Nobody in particular
Requestors: DDICK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.13b
Fixed in: (no value)



Currently, Archive::Ar does not pad the file contents to an even number of bytes as described in http://en.wikipedia.org/wiki/Ar_(file_format) This causes Archive::Ar to create archives that are reported as corrupted by ar.
Subject: Archive-Ar-1.13b.patch
diff -Naur old/lib/Archive/Ar.pm new/lib/Archive/Ar.pm --- old/lib/Archive/Ar.pm 2003-05-08 13:53:38.000000000 +1000 +++ new/lib/Archive/Ar.pm 2006-03-27 19:39:31.398986529 +1000 @@ -252,10 +252,14 @@ $content->{uid} ||= ""; $content->{gid} ||= ""; - $outstr.= pack("A16A12A6A6A8A10", @$content{qw/name date uid gid mode size/}); $outstr.= ARFMAG; $outstr.= $content->{data}; + unless (((length($content->{data})) % 2) == 0) { + # Padding to make up an even number of bytes + # as described in http://en.wikipedia.org/wiki/Ar_(file_format) + $outstr.= "\n"; + } } return $outstr unless $filename; diff -Naur old/t/30write.t new/t/30write.t --- old/t/30write.t 1970-01-01 10:00:00.000000000 +1000 +++ new/t/30write.t 2006-03-27 19:39:39.982521060 +1000 @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w + +use Test::More (tests => 2); +use strict; + +BEGIN { + chdir 't' if -d 't'; + use lib '../blib/lib', 'lib/', '..'; +} + +use Archive::Ar(); + +my ($padding_archive) = new Archive::Ar(); +$padding_archive->add_data("test.txt", "here\n"); +my ($archive_results) = $padding_archive->write(); +ok(length($archive_results) == 74, "Archive::Ar pads un-even number of bytes successfully\n"); +$padding_archive = new Archive::Ar(); +$padding_archive->add_data("test.txt", "here1\n"); +$archive_results = $padding_archive->write(); +ok(length($archive_results) == 74, "Archive::Ar pads even number of bytes successfully\n");
This issue has been corrected in version 1.14, which I uploaded to CPAN today. Thanks for reporting it and including a patch. John