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

lib/diglib: fix integer overflow #2735

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/vector/diglib/spindex_rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ int dig_Wr_spidx_head(struct gvfile *fp, struct Plus_head *ptr)
unsigned char buf[6];
long length = 81; /* header length in bytes */
struct RTree *t;
size_t size;

dig_rewind(fp);
dig_set_cur_port(&(ptr->spidx_port));

/* use ptr->off_t_size = 4 if possible */
if (sizeof(off_t) > 4) {
off_t size;

size = 145; /* max header size, see below */
size += ptr->Node_spidx->n_nodes * ptr->Node_spidx->nodesize;
size += ptr->Line_spidx->n_nodes * ptr->Line_spidx->nodesize;
size += ptr->Area_spidx->n_nodes * ptr->Area_spidx->nodesize;
size += ptr->Isle_spidx->n_nodes * ptr->Isle_spidx->nodesize;
size += (off_t)ptr->Node_spidx->n_nodes * ptr->Node_spidx->nodesize;
size += (off_t)ptr->Line_spidx->n_nodes * ptr->Line_spidx->nodesize;
size += (off_t)ptr->Area_spidx->n_nodes * ptr->Area_spidx->nodesize;
size += (off_t)ptr->Isle_spidx->n_nodes * ptr->Isle_spidx->nodesize;

if (size < PORT_INT_MAX)
ptr->spidx_port.off_t_size = 4;
Expand Down Expand Up @@ -282,6 +283,7 @@ int dig_Rd_spidx_head(struct gvfile *fp, struct Plus_head *ptr)
ptr->version.spidx.back_major, ptr->version.spidx.back_minor);

G_debug(2, " byte order %d", byte_order);
G_debug(2, " off_t size %d", ptr->spidx_port.off_t_size);

/* check version numbers */
if (ptr->version.spidx.major > GV_SIDX_VER_MAJOR ||
Expand Down Expand Up @@ -1158,9 +1160,9 @@ static void rtree_load_from_sidx(struct gvfile *fp, off_t rootpos,
struct RTree *t, int off_t_size)
{
if (t->fd > -1)
return rtree_load_to_file(fp, rootpos, t, off_t_size);
rtree_load_to_file(fp, rootpos, t, off_t_size);
else
return rtree_load_to_memory(fp, rootpos, t, off_t_size);
rtree_load_to_memory(fp, rootpos, t, off_t_size);
}

/*!
Expand Down