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
segfault while processing GetFeatureInfo #4403
segfault while processing GetFeatureInfo #4403
Conversation
hi, I've tracked down your issue and managed to reproduce it. For some reason or another, proj.4 is failing to reproject the query point, and the featureinfo writing code chokes on this, which is clearly a bug. We can fix the segfault but the resultset will be empty which is incorrect. I'm not a gis/projection guru, can you confirm that the queried point is actually valid for your raster projection? If so there's a bug in proj that would need to be adressed. |
I've just proposed a fix that also adds a more verbose proj error message, which gives:
|
Hi Thomas, Thanks for looking into this! I am pretty sure that the query point is valid, because I generated it by In the meantime, it would be helpful to me to know the exact coordinates, Doing the math myself, I'm thinking that the EPSG:3857 coordinates of the Also, it might be a good idea to add those coordinates to the error message Thanks again, --Mark On Mon, Jul 23, 2012 at 6:00 AM, Thomas Bonfort <
|
I suspect there's some adjustment related to the centering of the query point w.r.t. the pixel. The query point that's failing is |
I agree; those coords are close enough to what I got that I imagine the Note, though, that the proj command-line utility seems perfectly happy to #! /bin/bash echo '-11842309.595810996 4703658.4663789356' | invproj -f "%6f" +proj=merc echo '-106.381277 38.874135' | proj +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 The first call, to invproj, converts the original point from EPSG:3857 to The second call, to proj, converts the lon/lat returned by the first call -106.381277 38.874135 Just as an extra sanity check, I even did the conversion back in the other I'm able to do all this with the same version of proj that has been So, I'm wondering if the problem has something to do with the way that I'm happy to help debug this, but could you help me out by pointing me to Thanks! --Mark On Tue, Jul 24, 2012 at 4:04 AM, Thomas Bonfort <
|
I'll be offline till the beginning of next week so won't be able to help much more until then. here's the callstack of the failing proj call:
the tolerance error seems to be coming from: rh = hypot(xy.x, xy.y);
if ((lp.phi = rh * .5 ) > 1.) I_ERROR; which is around line 148 in PJ_laea.c of a more-or-less trunk version of proj |
@embeepea any update on this one ? |
Sorry, I haven't had a chance to get back to this --- I've been busy with On Tue, Jul 31, 2012 at 6:10 AM, Thomas Bonfort <
|
also add proj error message as to why reprojection failed
I've committed the fix that prevents the segfault into 6.2. Leaving this issue opened but demilestoning it for now. |
OK, I finally got back to this after several weeks on another project. The short version of the situation is that I think I may have found the problem, and I have a proposed fix for it. This involves code that I only have a very sketchy understanding of, though, so please scrutinize my solution closely to make sure it looks correct, and let me know if I'm way off base! I've forked the MapServer repo and pushed a commit to my fork that has my changes; you can check it out at
Both of the tests that I submitted originally with this issue run correctly with this fix, and it seems to correctly fix the coordinate issue I describe below. Here's a longer explanation: It looks to me like the problem has to do with MapServer's reprojection of the coordinates of the "hit" pixel into the SRS of the map. In particular, look at the following results. For the query string
MapServer returns the following GML:
This is the first test case of the two cases I submitted --- this is the one that does NOT crash. Look closely at coordinates in the query string. If I'm interpreting it correctly, the query is asking MapServer for information about what is at the location X=913 Y=334 in a 1514 x 689 pixel image whose extent (BBOX) is
expressed in the SRS EPSG:3857. The response says that it found a result in layer1, whose pixel value is 126, and whose coordinates in SRS EPSG:3857 are X=8935763.864626, Y=-5609465.555845. But those coordinates are not even in the BBOX of the query! I'll admit that I'm making a few unverified (I haven't read the WMS GetFeatureInfo spec) assumptions here about the meaning of the values in the WMS request and response, and if I'm wrong about this and need to formulate my query string differently, just let me know, and I apologize for taking up your time! But if my interpretation is correct, I think there's a problem with MapServer's handling of the coordinates of the "hit" region, and this problem happens universally --- not just in the version of my test that was causing a segfault. I suspect that the reason it segfaults only in some cases and not others is that the values being handed to proj cross certain thresholds in some cases but not others. But in all cases the result that proj returns is invalid. After studying the MapServer source for quite a while, it looks to me like what is happening is that sRasterQueryByRectLow() in maprasterquery.c is converting the query point into the mp SRS in order to do its distance calculation in those coordinates. If it finds a hit, it loads the query results with those query point coordinates which have been converted to the map SRS. The problem is that the code that formulates the GML response expects the results to be in the layer's SRS, and it's invoking proj to convert them to the map SRS. So the problem seems to be one too many coordinate transformations! The fix that I came up with is to change msRasterQueryByRectLow() so that it loads the results cache with the original layer SRS version of the query point. I'm not familiar enough with all the assumptions made in the code to know for sure that this is the correct solution, but it seems to work for my test case. Please take a look at it and let me know what you think! Thanks again, --Mark |
@embeepea I'm not enough into raster queries to be able to make an informed comment on your fix. maybe @warmerdam can have a look ? |
My apologies, when I saw Thomas fully engaged I let this drop of my radar. If Frank is around he's obviously in the best place to comment. Otherwise I know the query operations well. With the test case and the repo I should be able to work on this one. --Steve |
Thanks. Steve or Frank, see my comment #4403 (comment) from a couple of weeks ago for the details of what I found when I looked into this. A short summary of the situation is this: it looks to me, at least in the test case that I came up with, that MapServer is converting the coordinates of the raster query point from the layer SRS to the map SRS twice:
This results in invalid coordinates, and sometimes causes proj to barf. The fix that I came up with (see my forked repo at https://github.com/embeepea/mapserver) was to modify msRasterQueryByRectLow so that it returns the hit point coordinates in the layer SRS, instead of converting to the map SRS. This seems to fix my test case, but I'm not familiar enough with the assumptions in the MapServer code to know for sure that it's the correct thing to do. The other possibility would be to let msRasterQueryByRectLow() do the conversion, and change msGMLWriteQuery to not do it; which one is correct just depends on what assumptions are in place regarding how data should be returned from the low level query code. If I can be of more help in figuring this out, let me know! Thanks, --Mark On Fri, Sep 7, 2012 at 9:57 AM, Steve Lime notifications@github.com wrote:
|
For the record, the proposed modification is in aa59fd5 |
@sdlime, seems like Frank won't be looking into this. The proposed change seems reasonable to me, could this make it into 6.2 ? I'll take care of running the testsuite to see if this has some other side-effects, but would be grateful if you could have a quick look. thanks, thomas |
change msRasterQueryByRectLow() to give pixel location results in layer SRS not map SRS
ok, I'll bite the bullet and bring this in for 6.2. I've added two raster querying tests that clearly show that something was wrong. In https://github.com/mapserver/msautotest/blob/86960175ace0601afe9f57630200066afce50139/wxs/expected/wms_rast_featureinfo_reproj.xml#L14 , before this patch the bounds would end up as
instead of now as
I still needed to fix one last thing: in https://github.com/mapserver/msautotest/blob/86960175ace0601afe9f57630200066afce50139/wxs/expected/wms_rast_featureinfo_reproj.xml#L17 , the x and y values of the query point where being returned in map srs, they are now in layer srs. In my previous commit, I have made these modifications:
|
I can have a look later today if that helps... --Steve |
@sdlime just a quick look should be enough. The raster querying code is a bit particular in the sense that it puts the geometry information in the result shape and values. One goes through reprojection, and of course not the other, which ends up in us having to store both the projected and original pixel locations. |
Guys, Sorry - I didn't notice this was associated with me, and I am not clear on Best regards,
|
@warmerdam, thanks. The proposed patch can be seen here: https://github.com/tbonfort/mapserver/commit/c65723a45d2c979072f002a58c054a8c5ca6b162 , it has the inconvenience of having to add two members to the lrinfo struct, but I don't see how differently we can be doing this without being backwards incompatible with the current behavior that adds x and y to the feature attributes. |
Guys, Thanks for looking into this; let me know if I can be of any more help with --Mark On Sat, Sep 29, 2012 at 11:49 AM, Thomas Bonfort
|
also add proj error message as to why reprojection failed
change msRasterQueryByRectLow() to give pixel location results in layer SRS not map SRS
I have a raster layer (actually, a bunch of them) where MapServer sometimes segfaults when serving a GetFeatureInfo request, depending on the coordinate of the point being queried. I have come up with a couple of test cases, which are exactly identical to each other except for the value of X in the GetFeatureInfo request. In one case, X=913, and MapServer correctly processes the GetFeatureInfo request and returns correct results. In the other case, X=912, and MapServer segfaults. Both of these values of X are valid, and both correspond to pixels in the image where MapServer correctly displays the raster in question when called with a GetMap request.
My hunch is that the problem might be related to a misconfiguration of MapServer on my part, or a misconfiguration of the projections involved. The layer data is in a LAEA projection, and due to constraints on the project that are beyond my control, I have MapServer reprojecting it to a bizarre web mercator projection (EPSG 3857, aka EPSG 3785) for output, so the GetFeatureInfo request is expressed in EPSG 3857. But I'm stumped as to what the problem could be, and having MapServer crash with a segmentation fault seems like an indication of some kind of bug, even if I've got a configuration error.
I've tried turning on debugging in the mapfile, but nothing useful shows up in the log file.
I've tested this with several versions of MapServer, including 6.0.3 and 6.2-beta1, with the same results. I'm running these tests on a CentOS 6.2 system, compiling MapServer with the options --with-proj --with-ogr --with-gdal --with-wfs --with-wcs --with-wms --with-wmsclient --with-wfsclient and --with-php=/usr/include/php, and using gdal 1.7.2 and
proj 4.7.0.
My mapfile is appended below, along with the two test requests I mentioned above.
The layer data file that I am using is too big to attach to this email, but I've created a tgz file containing everything needed to run my tests -- the mapfile, layer file, and test script; you can download it here:
Here is the mapfile I am using:
And here are the two query strings for the two test cases:
this one runs correctly:
map=./mapfile.map&TRANSPARENT=true&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&STYLES=&FORMAT=image/png&INFO_FORMAT=application/vnd.ogc.gml&BBOX=-11859604.53136514,4696887.582602486,-11830673.11615924,4710053.860724591&CRS=EPSG:3857&LAYERS=layer1&QUERY_LAYERS=layer1&WIDTH=1514&HEIGHT=689&X=913&Y=334
this one causes a seg fault:
map=./mapfile.map&TRANSPARENT=true&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&STYLES=&FORMAT=image/png&INFO_FORMAT=application/vnd.ogc.gml&BBOX=-11859604.53136514,4696887.582602486,-11830673.11615924,4710053.860724591&CRS=EPSG:3857&LAYERS=layer1&QUERY_LAYERS=layer1&WIDTH=1514&HEIGHT=689&X=912&Y=334