Skip to content

Comments

lib/diglib: calculate the total size of topo file to get the correct off_t_size#3351

Merged
echoix merged 4 commits intoOSGeo:mainfrom
HuidaeCho:diglib_topo_offset
Feb 2, 2024
Merged

lib/diglib: calculate the total size of topo file to get the correct off_t_size#3351
echoix merged 4 commits intoOSGeo:mainfrom
HuidaeCho:diglib_topo_offset

Conversation

@HuidaeCho
Copy link
Member

@HuidaeCho HuidaeCho commented Jan 9, 2024

Creating a new PR for #3163 (accidentally merged instead of rebase).

off_t sizes for coor and topo files can be different. For example, from an EPSG:4326 location,

> v.mkgrid map=grids_00625deg position=coor coor=-180,-90 box=0.0625,0.0625 grid=2880,5760
> d.mon wx0
> d.vect grids_00625deg
ERROR: Unable to seek: Invalid argument

> ls -al .../vector/grids_00625deg
-rw-r--r-- 1 hcho users 1708966098 Sep 17 22:35 coor
-rw-r--r-- 1 hcho users         95 Sep 17 22:33 dbln
-rw-r--r-- 1 hcho users        173 Sep 17 22:33 head
-rw-r--r-- 1 hcho users        260 Sep 17 22:33 hist
-rw-r--r-- 1 hcho users 6706995200 Sep 17 22:45 sidx
-rw-r--r-- 1 hcho users 2173694570 Sep 17 22:45 topo

coor_size is less than PORT_LONG_MAX (2^31 - 1 = 2147483647; max int), but the topo size is greater than that. Setting ptr->off_t_size = 4 in

if (ptr->coor_size > (off_t)PORT_LONG_MAX) {
/* can only happen when sizeof(off_t) == 8 */
ptr->off_t_size = 8;
}
else
ptr->off_t_size = 4;
causes an integer overflow and ptr->Isle_offset is read as -2121341854 in
if (0 >= dig__fread_port_O(&(ptr->Isle_offset), 1, fp, ptr->off_t_size))

This PR calculates the total size of topo file to get the correct off_t_size. Before this PR, the size of coor file was used to determine this offset size for topo file.

@github-actions github-actions bot added C Related code is in C libraries labels Jan 9, 2024
@HuidaeCho HuidaeCho self-assigned this Jan 23, 2024
@github-actions github-actions bot added the vector Related to vector data processing label Jan 23, 2024
Copy link
Contributor

@metzm metzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this bugfix!

@echoix
Copy link
Member

echoix commented Jan 27, 2024

This PR is approved and reviewed. Is there anything that should block merging this?

@echoix echoix enabled auto-merge (squash) February 1, 2024 23:29
@echoix echoix merged commit 13a7936 into OSGeo:main Feb 2, 2024
neteler pushed a commit that referenced this pull request Feb 2, 2024
…t_size (#3351)

* diglib: Calculate the total size of topo file to get the correct off_t_size

* Add doxygen API doc for dig_Wr_Plus_head()

* cast long PORT_LONG_MAX into off_t
@neteler neteler modified the milestones: 8.4.0, 8.3.2 Feb 2, 2024
jadenabrams100 pushed a commit to ncsu-csc472-spring2024/grass-CI-playground that referenced this pull request Feb 21, 2024
…t_size (OSGeo#3351)

* diglib: Calculate the total size of topo file to get the correct off_t_size

* Add doxygen API doc for dig_Wr_Plus_head()

* cast long PORT_LONG_MAX into off_t
@neteler neteler changed the title diglib: Calculate the total size of topo file to get the correct off_t_size lib/diglib: calculate the total size of topo file to get the correct off_t_size Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C libraries vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants