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

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

Closed
vaclavblazek opened this issue Jun 23, 2016 · 3 comments
Closed
Labels
Milestone

Comments

@vaclavblazek
Copy link

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
Copy link
Member

rouault commented Jun 23, 2016

Would you mind submitting this fix as a pull request ?

@kbevers
Copy link
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 rouault added this to the 4.9.4 milestone Feb 26, 2017
@rouault
Copy link
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 as completed 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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants