chiark / gitweb /
Cope when an orig tarball is a tarbomb.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 7 Nov 2016 23:12:42 +0000 (23:12 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 7 Nov 2016 23:55:31 +0000 (23:55 +0000)
Ie, if it contains other than one single directory toplevel.
Closes:#843422.

Specifically:

 * We change the unpack directory to _unpack-tar in unpack, rather
   than ../unpack-tar.  This means that mktree_in_ud DTRT in that
   directory, rather than in its supposed only subdiredctory
 * We do write-tree on the whole tarball.
 * Then if the tarball had only one subdir in it, we fish the
   subtree's tree object out of the git tree object.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
debian/changelog
dgit

index 691b783dbf825a1f31741ad4ee577b6a080c7348..41f2796cd6066c2bdafe7e3bb8a71b7d6e40a6e6 100644 (file)
@@ -12,6 +12,8 @@ dgit (2.10~) unstable; urgency=medium
     so that users can easily track "jessie, or jessie-security".
   * Fix an unconditional print that was supposed to be a printdebug:
       origs <blah>.orig.tar.gz f.same=1 #f._differ=-1
+  * Cope when an orig tarball is a tarbomb.  Ie, if it contains
+    other than one single directory toplevel.  Closes:#843422.
 
  --
 
diff --git a/dgit b/dgit
index 89795013c12804a47ddefa9b59caee9adae63194..4f54379ecdf3f0886d028ca8b0056b0935d1e9fb 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -2128,14 +2128,14 @@ sub generate_commits_from_dsc () {
            $input = $compr_fh;
        }
 
-       rmtree "../unpack-tar";
-       mkdir "../unpack-tar" or die $!;
+       rmtree "_unpack-tar";
+       mkdir "_unpack-tar" or die $!;
        my @tarcmd = qw(tar -x -f -
                        --no-same-owner --no-same-permissions
                        --no-acls --no-xattrs --no-selinux);
        my $tar_pid = fork // die $!;
        if (!$tar_pid) {
-           chdir "../unpack-tar" or die $!;
+           chdir "_unpack-tar" or die $!;
            open STDIN, "<&", $input or die $!;
            exec @tarcmd;
            die "dgit (child): exec $tarcmd[0]: $!";
@@ -2149,11 +2149,21 @@ sub generate_commits_from_dsc () {
        # finally, we have the results in "tarball", but maybe
        # with the wrong permissions
 
-       runcmd qw(chmod -R +rwX ../unpack-tar);
-       changedir "../unpack-tar";
-       my ($tree) = mktree_in_ud_from_only_subdir(1);
-       changedir "../../unpack";
-       rmtree "../unpack-tar";
+       runcmd qw(chmod -R +rwX _unpack-tar);
+       changedir "_unpack-tar";
+       remove_stray_gits();
+       mktree_in_ud_here();
+       
+       my ($tree) = git_add_write_tree();
+       my $tentries = cmdoutput @git, qw(ls-tree -z), $tree;
+       if ($tentries =~ m/^\d+ tree (\w+)\t[^\000]+\000$/s) {
+           $tree = $1;
+           printdebug "one subtree $1\n";
+       } else {
+           printdebug "multiple subtrees\n";
+       }
+       changedir "..";
+       rmtree "_unpack-tar";
 
        my $ent = [ $f, $tree ];
        push @tartrees, {