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

pj_apply_vgridshift accesses point outside of grid (segmentation fault) #396

Closed
vaclavblazek opened this Issue Jun 23, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@vaclavblazek

vaclavblazek commented Jun 23, 2016

When you happen to transform point on the edge of vertical shift grid file (e.g. at the south pole) the bilinear interpolation code accesses point outside of grid limits due to nature of bilinear interpolation which samples points (x, y), (x + 1, y), (x, y + 1), (x + 1, y + 1). Coordinates x and y are checked against limits but (x + 1) and (y + 1) are left unchecked. This causes undefined behaviour that sometimes leads to program crash (segmentation fault).

I've fixed the function in our installation by replacing 1 with variables next_x and next_y that are set to 1 everywhere except at the grid's right and bottom border. This effectively replicates values at border.

            int next_x, next_y;
...
            next_x = ((grid_ix + 1) < ct->lim.lam);
            next_y = ((grid_iy + 1) < ct->lim.phi);
...
            value = cvs[grid_ix + grid_iy * ct->lim.lam] 
                * (1.0-grid_x) * (1.0-grid_y)
                + cvs[grid_ix + next_x + grid_iy * ct->lim.lam] 
                * (grid_x) * (1.0-grid_y)
                + cvs[grid_ix + (grid_iy + next_y) * ct->lim.lam] 
                * (1.0-grid_x) * (grid_y)
                + cvs[grid_ix + next_x + (grid_iy + next_y) * ct->lim.lam] 
                * (grid_x) * (grid_y);
@rouault

This comment has been minimized.

Member

rouault commented Jun 23, 2016

Would you mind submitting this fix as a pull request ?

@kbevers

This comment has been minimized.

Member

kbevers commented Jun 28, 2016

@vaclavblazek Thanks for reporting this. Could you give us an example of a command line call that causes the segfault?

@kbevers kbevers added the bug label Oct 18, 2016

rouault added a commit that referenced this issue Feb 26, 2017

@rouault rouault added this to the 4.9.4 milestone Feb 26, 2017

@rouault

This comment has been minimized.

Member

rouault commented Feb 26, 2017

Note: I didn't try to replicate but hopefully the above commit should fix it.

@rouault rouault closed this Feb 26, 2017

@kbevers kbevers modified the milestones: 5.0.0-b, 5.0.0 Feb 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment