Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpm: Fix Visual Studio compiler warnings #2181

Merged
merged 3 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 21 additions & 14 deletions libarchive/archive_read_support_filter_rpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ struct rpm {
} state;
int first_header;
};
#define RPM_LEAD_SIZE 96 /* Size of 'Lead' section. */
#define RPM_LEAD_SIZE 96 /* Size of 'Lead' section. */
#define RPM_MIN_HEAD_SIZE 16 /* Minimum size of 'Head'. */

static int rpm_bidder_bid(struct archive_read_filter_bidder *,
struct archive_read_filter *);
Expand All @@ -63,6 +64,8 @@ static ssize_t rpm_filter_read(struct archive_read_filter *,
const void **);
static int rpm_filter_close(struct archive_read_filter *);

static inline size_t rpm_limit_bytes(uint64_t, size_t);

#if ARCHIVE_VERSION_NUMBER < 4000000
/* Deprecated; remove in libarchive 4.0 */
int
Expand Down Expand Up @@ -155,13 +158,19 @@ rpm_bidder_init(struct archive_read_filter *self)
return (ARCHIVE_OK);
}

static inline size_t
rpm_limit_bytes(uint64_t bytes, size_t max)
{
return (bytes > max ? max : (size_t)bytes);
}

static ssize_t
rpm_filter_read(struct archive_read_filter *self, const void **buff)
{
struct rpm *rpm;
const unsigned char *b;
ssize_t avail_in, total;
uint64_t used, n;
ssize_t avail_in, total, used;
size_t n;
uint64_t section;
uint64_t bytes;

Expand Down Expand Up @@ -197,15 +206,14 @@ rpm_filter_read(struct archive_read_filter *self, const void **buff)
}
break;
case ST_HEADER:
n = 16 - rpm->hpos;
if (n > avail_in - used)
n = avail_in - used;
n = rpm_limit_bytes(RPM_MIN_HEAD_SIZE - rpm->hpos,
avail_in - used);
memcpy(rpm->header+rpm->hpos, b, n);
b += n;
used += n;
rpm->hpos += n;

if (rpm->hpos == 16) {
if (rpm->hpos == RPM_MIN_HEAD_SIZE) {
if (rpm->header[0] != 0x8e ||
rpm->header[1] != 0xad ||
rpm->header[2] != 0xe8 ||
Expand All @@ -219,29 +227,28 @@ rpm_filter_read(struct archive_read_filter *self, const void **buff)
}
rpm->state = ST_ARCHIVE;
*buff = rpm->header;
total = rpm->hpos;
total = RPM_MIN_HEAD_SIZE;
break;
}
/* Calculate 'Header' length. */
section = archive_be32dec(rpm->header+8);
bytes = archive_be32dec(rpm->header+12);
rpm->hlen = 16 + section * 16 + bytes;
rpm->hlen = rpm->hpos + section * 16 + bytes;
rpm->state = ST_HEADER_DATA;
rpm->first_header = 0;
}
break;
case ST_HEADER_DATA:
n = rpm->hlen - rpm->hpos;
if (n > avail_in - used)
n = avail_in - used;
n = rpm_limit_bytes(rpm->hlen - rpm->hpos,
avail_in - used);
b += n;
used += n;
rpm->hpos += n;
if (rpm->hpos == rpm->hlen)
rpm->state = ST_PADDING;
break;
case ST_PADDING:
while (used < (size_t)avail_in) {
while (used < avail_in) {
if (*b != 0) {
/* Read next header. */
rpm->state = ST_HEADER;
Expand All @@ -259,7 +266,7 @@ rpm_filter_read(struct archive_read_filter *self, const void **buff)
used = avail_in;
break;
}
if (used == (size_t)avail_in) {
if (used == avail_in) {
rpm->total_in += used;
__archive_read_filter_consume(self->upstream, used);
b = NULL;
Expand Down