Rather than relying on a regex, detect directories in the uploaded
tarball and count the slashes. This avoids problems with bsdtar
inserting PaxHeader attributes into the archive which look something
like the following to Archive_Tar:

  PaxHeader/xcursor-protozoa
  xcursor-protozoa/
  xcursor-protozoa/PaxHeader/PKGBUILD
  xcursor-protozoa/PKGBUILD

This only occurs on certain filesystems (e.g. jfs), but the tarball is
by no means invalid. When extracted, it will only contain the PKGBUILD
within a single subdirectory.

Signed-off-by: Dave Reisner <[email protected]>
---
 web/html/pkgsubmit.php |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php
index 75a4b69..5f5ba30 100644
--- a/web/html/pkgsubmit.php
+++ b/web/html/pkgsubmit.php
@@ -63,16 +63,13 @@ if ($uid):
 
                        # Extract PKGBUILD into a string
                        $pkgbuild_raw = '';
-                       $dircount = 0;
                        foreach ($tar->listContent() as $tar_file) {
                                if (preg_match('/^[^\/]+\/PKGBUILD$/', 
$tar_file['filename'])) {
                                        $pkgbuild_raw = 
$tar->extractInString($tar_file['filename']);
                                }
-                               elseif (preg_match('/^[^\/]+\/$/', 
$tar_file['filename'])) {
-                                       if (++$dircount > 1) {
-                                               $error = __("Error - source 
tarball may not contain more than one directory.");
-                                               break;
-                                       }
+                               elseif ($tar_file['filetype'] == 5 && 
count(explode(',', $tar_file['filename'])) > 1) {
+                                       $error = __("Error - source tarball may 
not contain more than one directory.");
+                                       break;
                                }
                                elseif (preg_match('/^[^\/]+$/', 
$tar_file['filename'])) {
                                        $error = __("Error - source tarball may 
not contain files outside a directory.");
-- 
1.7.9.4

Reply via email to