Bug 47504 - read/write -1 bytes
Summary: read/write -1 bytes
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: rpm
Version: 1.0
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact: David Lawrence
Depends On:
TreeView+ depends on / blocked
Reported: 2001-07-05 19:41 UTC by Nathan Owen
Modified: 2007-04-18 16:34 UTC (History)
0 users

Clone Of:
Last Closed: 2001-08-01 21:45:42 UTC

Attachments (Terms of Use)
this is the output from rpm -qp ~/rpms/sed-3.02-9.src.rpm --rpmiodebug (5.34 KB, text/plain)
2001-07-05 22:01 UTC, Nathan Owen
no flags Details

Description Red Hat Bugzilla 2001-07-05 19:41:45 UTC
Description of Problem:
When rpm reads or writes to/from a package it will always pass the value -1
to read or write as the (unsigned) number of bytes to read/write. On linux
this appears to work (accidentaly I would hope) but solaris to catches this
and returns an error (errno 22, Invalid Argument).

How Reproducible:
rpm -qp somepackage.rpm
rpm -ba somepackage.spec
This will work on linux, but fail on solaris

Additional Information:
I think this is because neither fd->contentLength nor fd->bytesRemain is
ever set to anything but -1 before fdRead or fdWrite is called.

It appears to work if the sign bit of fd->bytesRemain is masked out, but
this is a hack and I am working on a patch with a "better" way to fix this.

Comment 1 Red Hat Bugzilla 2001-07-05 19:50:56 UTC
Can you append the output of an example with --rpmiodebug set?
That should be enough for me to figger what's up and get a fix
in place, as the rpmio code is guaranteed to make your head hurt :-)

Comment 2 Red Hat Bugzilla 2001-07-05 22:01:27 UTC
Created attachment 22827 [details]
this is the output from rpm -qp ~/rpms/sed-3.02-9.src.rpm --rpmiodebug

Comment 3 Red Hat Bugzilla 2001-07-08 15:41:31 UTC
Here's the relevant piece:

=> Ferror(2f6d0) rc 0  | UFD 6 fp 0
==> Fileno(2f6d0) rc 6  | UFD 6 fp 0
==>     fdRead(2f6d0,efffe190,96) rc -1         | UFD 6 fp 0
*** read: rc -1 errno 22 Invalid argument ""
error: read failed: Invalid argument (22)
==> Fclose(2f6d0)       | UFD 6 fp

Here's the code:
    rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain :

The underlying issue is multiplexing mutiple I/O streams across an open file
descriptor of, say, a persistent HTTP/1.1 connection, so fdRead() needs to
simulate EOF based on ContentLength:.  value, if present.

So the problem seems to be with the ssize_t prototype being treated
differently on Solaris in read(2) (from rpmio/rpmio_internal.h)
   ssize_t     bytesRemain;
   ssize_t     contentLength;

Ah yes, the comparison on linux is (casts added for clatity) unsigned
	((size_t)count) > ((ssize_t)fd->bytes_remain)

so the problem is (I predict) that size_t is int, not unsigned, on
Solaris. If that's the case, I can get an unsigned cast in place
throughout rpmio comparisons in a jiffy.

Comment 4 Red Hat Bugzilla 2001-07-16 16:12:09 UTC
Well a size_t is being defined as an unsigned int in sys/types.h, and when I
tried it that cast had no effect.

after rereading the manpage for read I noticed this line:
     If the value of nbyte is greater than SSIZE_MAX, the  result
     is implementation-dependent.

It looks to me like the implementation in solaris 2.6 just considers this to be
an error.

Comment 5 Red Hat Bugzilla 2001-08-01 20:55:05 UTC

Since we use rpm on a lot of platforms (including Solaris) too, I just built rpm
from CVS
on a Solaris 2.8 box, and I can't reproduce this problem.  Do you have Solaris
and is the problem happening there too?  Other than some build issues, rpm from
CVS has worked for the few tests I've tried.

I tried building rpm from CVS on 2.6, but the db-3.3.11 build (part of rpm)
Solaris' `ar' command to core dump, and I can't take any of our 2.6 systems down
to apply the latest patch bundle to see if the problem goes away.

Comment 6 Red Hat Bugzilla 2001-08-01 21:45:37 UTC
Unfortunately I only have access to 2.6 systems here so I can't say anything
about 2.7 or 2.8. 

I cannot reach the CVS server from work so I've been working with the rawhide
packages and building them with the GNUpro tools so I don't know whether the
patches from Sun would fix your problem.

FWIW I'm using GNU ar 2.9-gnupro-99r1

Other than this one, I have not found any problems with rpms behavior beyond
some build issues (most of them have already gotten into CVS). I have a rather
trivial patch that fixes this problem if you get past your build problem.

Comment 7 Red Hat Bugzilla 2001-08-04 18:36:53 UTC
So far this problem is localized to a single solaris 2.6 box (sorry Nathan),
I'm gonna defer this problem until someone tells me what the right
thing to do is.

Note You need to log in before you can comment on or make changes to this bug.