From frank@dynamical-systems.org  Mon Nov  6 17:16:12 2006
Return-Path: <frank@dynamical-systems.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 763B316A415
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  6 Nov 2006 17:16:12 +0000 (UTC)
	(envelope-from frank@dynamical-systems.org)
Received: from mout2.freenet.de (mout2.freenet.de [194.97.50.155])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 5515C43D90
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  6 Nov 2006 17:15:01 +0000 (GMT)
	(envelope-from frank@dynamical-systems.org)
Received: from [194.97.55.242] (helo=mx9.freenet.de)
	by mout2.freenet.de with esmtpa (Exim 4.62)
	(envelope-from <frank@dynamical-systems.org>)
	id 1Gh83k-000523-5O
	for FreeBSD-gnats-submit@freebsd.org; Mon, 06 Nov 2006 18:14:56 +0100
Received: from p508eaa16.dip0.t-ipconnect.de ([80.142.170.22]:59468 helo=pollux.senax.net)
	by mx9.freenet.de with esmtpsa (ID jr-relay@freenet.de) (TLSv1:AES256-SHA:256) (port 25) (Exim 4.62 #12)
	id 1Gh83j-0000a3-LA
	for FreeBSD-gnats-submit@freebsd.org; Mon, 06 Nov 2006 18:14:56 +0100
Received: from pollux.senax.net (localhost.senax.net [127.0.0.1])
	by pollux.senax.net (8.13.6/8.13.6) with ESMTP id kA6H7ORE001978;
	Mon, 6 Nov 2006 18:07:24 +0100 (CET)
	(envelope-from frank@dynamical-systems.org)
Received: (from josellis@localhost)
	by pollux.senax.net (8.13.6/8.13.6/Submit) id kA6H79oB001976;
	Mon, 6 Nov 2006 18:07:09 +0100 (CET)
	(envelope-from frank@dynamical-systems.org)
Message-Id: <200611061707.kA6H79oB001976@pollux.senax.net>
Date: Mon, 6 Nov 2006 18:07:09 +0100 (CET)
From: "Frank W. Josellis" <frank@dynamical-systems.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: patch: archivers/unmakeself - extraction fails under certain conditions
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         105214
>Category:       ports
>Synopsis:       patch: archivers/unmakeself - extraction fails under certain conditions
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    jylefort
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 06 17:20:19 GMT 2006
>Closed-Date:    Mon Nov 06 20:15:49 GMT 2006
>Last-Modified:  Tue Nov  7 16:10:18 GMT 2006
>Originator:     Frank W. Josellis
>Release:        FreeBSD 5.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD pollux.senax.net 5.5-STABLE FreeBSD 5.5-STABLE #11: Fri Oct 27 20:51:49 CEST 2006 root@pollux.senax.net:/usr/obj/usr/src/sys/POLLUX i386


	
>Description:
It appears that the offset calculation is not always correct. The approach
fails in an obvious way if the first line of an archive consists entirely of
printable characters. Unfortunately, this can indeed happen, an example
is the latest GoogleEarthLinux.bin (version 4.0.2414). Please consider the
patch below for a different method to determine the offset.  

>How-To-Repeat:
fetch http://dl.google.com/earth/GE4/GoogleEarthLinux.bin

unmakeself GoogleEarthLinux.bin

>Fix:

	

--- unmakeself.patch begins here ---
diff -Nur unmakeself.orig/files/unmakeself.c unmakeself/files/unmakeself.c
--- unmakeself.orig/files/unmakeself.c	Sun Jun 12 20:17:05 2005
+++ unmakeself/files/unmakeself.c	Mon Nov  6 14:36:53 2006
@@ -43,6 +43,8 @@
 #include <getopt.h>
 #include <archive.h>
 
+#define BUFSIZE 4096
+
 static char *self = NULL;				/* program name */
 static int extract_flags = ARCHIVE_EXTRACT_TIME;	/* bsdtar default */
 
@@ -70,6 +72,36 @@
   printf("Copyright (C) 2005 Jean-Yves Lefort\n");
 }
 
+static int
+unmakeself_get_offset (const char *filename)
+{
+  int offset = -1;
+  int skip = 0;
+  char buf[BUFSIZE];
+  FILE *stream;
+
+  /* Let the script tell us the number of header lines. */
+  snprintf(buf, BUFSIZE,
+	   "sh %s --dumpconf | grep OLDSKIP | cut -f2 -d=", filename);
+  stream = popen(buf, "r");
+  skip = atoi(fgets(buf, BUFSIZE, stream));
+  pclose(stream);
+
+  /* Scan the header lines to calculate the offset. */
+  if (skip) {
+    int i;
+    
+    stream = fopen(filename, "r");
+    for (i = 0; i < skip - 1; i++) {
+      fgets(buf, BUFSIZE, stream);
+      offset += strlen(buf);
+    }
+    fclose(stream);
+    offset++;
+  }
+  return(offset);
+}
+
 static void
 unmakeself_extract (const char *filename, int print_offset)
 {
@@ -93,6 +125,7 @@
    * by locating the first non-printable character following a
    * newline. The archive starts immediately after that newline.
    */
+  /*
   while (! done && (len = read(fd, buf, sizeof(buf))) > 0)
     {
       int i;
@@ -109,7 +142,9 @@
 	    break;
 	  }
     }
+  */
 
+  offset = unmakeself_get_offset(filename);
   if (offset != -1)		/* offset found */
     {
       if (print_offset)		/* only print the offset */
--- unmakeself.patch ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->jylefort 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Nov 6 17:20:55 UTC 2006 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105214 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/105214: commit references a PR
Date: Mon,  6 Nov 2006 20:09:12 +0000 (UTC)

 jylefort    2006-11-06 20:08:48 UTC
 
   FreeBSD ports repository
 
   Modified files:
     archivers/unmakeself Makefile 
     archivers/unmakeself/files unmakeself.c 
   Log:
   - Fix archive offset calculation (problem reported in [1])
   - Various code cleanups
   
   [1]:
   PR:             ports/105214
   Submitted by:   Frank W. Josellis <frank@dynamical-systems.org>
   
   Revision  Changes    Path
   1.5       +12 -12    ports/archivers/unmakeself/Makefile
   1.3       +126 -83   ports/archivers/unmakeself/files/unmakeself.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: jylefort 
State-Changed-When: Mon Nov 6 20:10:43 UTC 2006 
State-Changed-Why:  
Good catch. However I do not want to execute the script (I don't think the 
command line options are consistent across versions), so I now check for 
gzip/bzip2 magic numbers, and if it does not work I fallback to the 
previous "printable" method. Thanks for the patch anyway. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105214 

From: "Frank W. Josellis" <frank@dynamical-systems.org>
To: Jean-Yves Lefort <jylefort@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/105214: patch: archivers/unmakeself - extraction fails
 under certain conditions
Date: Tue, 7 Nov 2006 14:58:14 +0100 (CET)

 Thanks for your prompt action, it's ok now with RELENG_6. But on RELENG_5 
 (and earlier) we're still in trouble: memmem() is not adopted here.
 
 I remember to have encountered this problem earlier with GNUish software, 
 and I had to introduce memmem() explicitly to make it work.
 

From: Jean-Yves Lefort <jylefort@FreeBSD.org>
To: "Frank W. Josellis" <frank@dynamical-systems.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/105214: patch: archivers/unmakeself - extraction fails
 under certain conditions
Date: Tue, 7 Nov 2006 17:08:02 +0100

 --Signature=_Tue__7_Nov_2006_17_08_02_+0100_HXy0Ky8=ecDYEU.G
 Content-Type: text/plain; charset=US-ASCII
 Content-Disposition: inline
 Content-Transfer-Encoding: 7bit
 
 On Tue, 7 Nov 2006 14:58:14 +0100 (CET)
 "Frank W. Josellis" <frank@dynamical-systems.org> wrote:
 
 > Thanks for your prompt action, it's ok now with RELENG_6. But on RELENG_5
 > (and earlier) we're still in trouble: memmem() is not adopted here.
 >
 > I remember to have encountered this problem earlier with GNUish software,
 > and I had to introduce memmem() explicitly to make it work.
 
 Fixed, thanks.
 
 --
 Jean-Yves Lefort
 
 jylefort@FreeBSD.org
 http://lefort.be.eu.org/
 
 --Signature=_Tue__7_Nov_2006_17_08_02_+0100_HXy0Ky8=ecDYEU.G
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.5 (FreeBSD)
 
 iD8DBQFFUK9iyzD7UaO4AGoRAs58AJ9FqdGmtPpZVV3dLx7OOckAtuOq2QCeMtft
 oHDEDQhZ1pAFpdrPd60Wr/Y=
 =7Uiv
 -----END PGP SIGNATURE-----
 
 --Signature=_Tue__7_Nov_2006_17_08_02_+0100_HXy0Ky8=ecDYEU.G--
 
>Unformatted:
