Sophie

Sophie

distrib > Mageia > 1 > i586 > media > core-updates-src > by-pkgid > 2d27fe3dff73e21c1aac97aebe0dff40 > files > 34

rpm-4.8.1-10.5.mga1.src.rpm

From: Panu Matilainen
Date: 22 Nov 2011
		
Right... I had forgotten just how much had changed in this area since 4.9.x and just how broken things had been.

The header reading IO has been hardwired to ufdio (see timedRead() in rpmio.c) for pretty much all of its life, eliminating any possibility of compressed io working. The other piece of the puzzle is rpm's libio usage which affects the rpm io semantics to vary between fread() and read() styles. Which the header stuff can't cope with, hence the hardwire to ufdio.

The attached patch makes my previous code snippet to read headers directly from compressed stream work on rpm-4.9.x too. It's essentially commit 3ab3a931b4dd84eedcb35229187e5be8d14f9418 from master + unconditionally disable libio usage. Rpm itself should be ok with this change as is (at least the test-suite still passes) but I can't guarantee it wont break anything else in your setup. Eg if you have code that's tuned to the exact semantics it had before... but then again it might just as well fix some "mysteriously broken things" for you.

diff -up rpm-4.8.1/lib/header.c.0160 rpm-4.8.1/lib/header.c
--- rpm-4.8.1/lib/header.c.0160	2012-02-29 22:46:17.717223536 +0100
+++ rpm-4.8.1/lib/header.c	2012-02-29 22:46:17.727223566 +0100
@@ -962,8 +962,7 @@ Header headerRead(FD_t fd, enum hMagic m
     if (magicp == HEADER_MAGIC_YES)
 	i += 2;
 
-    /* FIX: cast? */
-    if (timedRead(fd, (char *)block, i*sizeof(*block)) != (i * sizeof(*block)))
+    if (Fread(block, 1, i*sizeof(*block), fd) != i*sizeof(*block))
 	goto exit;
 
     i = 0;
@@ -989,8 +988,7 @@ Header headerRead(FD_t fd, enum hMagic m
     ei[1] = htonl(dl);
     len -= sizeof(il) + sizeof(dl);
 
-    /* FIX: cast? */
-    if (timedRead(fd, (char *)&ei[2], len) != len)
+    if (Fread((char *)&ei[2], 1, len, fd) != len)
 	goto exit;
     
     h = headerLoad(ei);
diff -up rpm-4.8.1/lib/package.c.0160 rpm-4.8.1/lib/package.c
--- rpm-4.8.1/lib/package.c.0160	2010-06-11 10:45:34.000000000 +0200
+++ rpm-4.8.1/lib/package.c	2012-02-29 22:46:17.727223566 +0100
@@ -468,7 +468,7 @@ static rpmRC rpmpkgReadHeader(rpmKeyring
 	*msg = NULL;
 
     memset(block, 0, sizeof(block));
-    if ((xx = timedRead(fd, (char *)block, sizeof(block))) != sizeof(block)) {
+    if ((xx = Fread(block, 1, sizeof(block), fd)) != sizeof(block)) {
 	rasprintf(&buf, 
 		_("hdr size(%d): BAD, read returned %d\n"), (int)sizeof(block), xx);
 	goto exit;
@@ -494,7 +494,7 @@ static rpmRC rpmpkgReadHeader(rpmKeyring
     ei = xmalloc(uc);
     ei[0] = block[2];
     ei[1] = block[3];
-    if ((xx = timedRead(fd, (char *)&ei[2], nb)) != nb) {
+    if ((xx = Fread((char *)&ei[2], 1, nb, fd)) != nb) {
 	rasprintf(&buf, _("hdr blob(%zd): BAD, read returned %d\n"), nb, xx);
 	goto exit;
     }
diff -up rpm-4.8.1/lib/rpmlead.c.0160 rpm-4.8.1/lib/rpmlead.c
--- rpm-4.8.1/lib/rpmlead.c.0160	2010-06-11 10:45:34.000000000 +0200
+++ rpm-4.8.1/lib/rpmlead.c	2012-02-29 22:46:17.727223566 +0100
@@ -117,8 +117,7 @@ rpmRC rpmLeadRead(FD_t fd, rpmlead lead)
 {
     assert(lead != NULL);
     memset(lead, 0, sizeof(*lead));
-    /* FIX: remove timed read */
-    if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
+    if (Fread(lead, 1, sizeof(*lead), fd) != sizeof(*lead)) {
 	if (Ferror(fd)) {
 	    rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"),
 			Fstrerror(fd), errno);
diff -up rpm-4.8.1/lib/signature.c.0160 rpm-4.8.1/lib/signature.c
--- rpm-4.8.1/lib/signature.c.0160	2009-12-07 15:36:49.000000000 +0100
+++ rpm-4.8.1/lib/signature.c	2012-02-29 22:46:17.727223566 +0100
@@ -124,7 +124,7 @@ rpmRC rpmReadSignature(FD_t fd, Header *
 	goto exit;
 
     memset(block, 0, sizeof(block));
-    if ((xx = timedRead(fd, (void *)block, sizeof(block))) != sizeof(block)) {
+    if ((xx = Fread(block, 1, sizeof(block), fd)) != sizeof(block)) {
 	rasprintf(&buf, _("sigh size(%d): BAD, read returned %d\n"), 
 		  (int)sizeof(block), xx);
 	goto exit;
@@ -155,7 +155,7 @@ rpmRC rpmReadSignature(FD_t fd, Header *
     ei[1] = block[3];
     pe = (entryInfo) &ei[2];
     dataStart = (unsigned char *) (pe + il);
-    if ((xx = timedRead(fd, (void *)pe, nb)) != nb) {
+    if ((xx = Fread(pe, 1, nb, fd)) != nb) {
 	rasprintf(&buf,
 		  _("sigh blob(%d): BAD, read returned %d\n"), (int)nb, xx);
 	goto exit;
@@ -244,7 +244,7 @@ rpmRC rpmReadSignature(FD_t fd, Header *
 	rpm_loff_t archSize = 0;
 
 	/* Position at beginning of header. */
-	if (pad && (trc = timedRead(fd, (void *)block, pad)) != pad) {
+	if (pad && (trc = Fread(block, 1, pad, fd)) != pad) {
 	    rasprintf(&buf,
 		      _("sigh pad(%zd): BAD, read %zd bytes\n"), pad, trc);
 	    goto exit;
diff -up rpm-4.8.1/rpmio/rpmio.c.0160 rpm-4.8.1/rpmio/rpmio.c
--- rpm-4.8.1/rpmio/rpmio.c.0160	2009-12-07 15:36:49.000000000 +0100
+++ rpm-4.8.1/rpmio/rpmio.c	2012-02-29 22:46:38.537284284 +0100
@@ -5,9 +5,7 @@
 #include "system.h"
 #include <stdarg.h>
 
-#if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
-#define	_USE_LIBIO	1
-#endif
+#define	_USE_LIBIO	0
 
 #include <rpm/rpmlog.h>
 #include <rpm/rpmmacro.h>
@@ -765,7 +763,7 @@ static const FDIO_t ufdio = &ufdio_s ;
 
 ssize_t timedRead(FD_t fd, void * bufptr, size_t length)
 {
-    return ufdio->read(fd, bufptr, length);
+    return Fread(bufptr, 1, length, fd);
 }
 
 /* =============================================================== */