Ticket #4278 (new defect)

Opened 20 months ago

Last modified 20 months ago

VizGeorefSpline2D::solve result not checked

Reported by: yavorr Owned by: warmerdam
Priority: normal Milestone:
Component: Algorithms Version: 1.8.1
Severity: normal Keywords: thin plate spline
Cc:

Description

The result of VizGeorefSpline?2D::solve is not checked in GDALCreateTPSTransformer.

If VizGeorefSpline?2D::solve fails the function still returns a not NULL result and the transformation becomes unpredictable.

The problem comes in solve:

// Invert the matrix
    int status = matrixInvert( _nof_eqs, _AA, _Ainv );
			
    if ( !status )
    {
        fprintf(stderr, " There is a problem to invert the interpolation matrix\n");
        return 0;
    }

while calculating matrixInvert:

ftemp = temp[ k*2*N + k ];
if ( ftemp == 0.0f ) // matrix cannot be inverted

I think there should be something like this in GDALCreateTPSTransformer:

if ( psInfo->poForward->solve() == 0 ||
     psInfo->poReverse->solve() == 0 )
{
   GDALDestroyTPSTransformer(psInfo);
   return NULL;
}

Change History

follow-up: ↓ 2   Changed 20 months ago by rouault

Suggested fix looks straightforward at first sight, but I'm wondering if there are not situations where one way can be solved successfully, ant the reverse one not, and that we should still want to be able to use the transformer in the way where it is valid. I have no solid facts to bring in however to tell if it justs one metaphysical worry or a practical one.

If both forward and reverse can't be solved, then obviously, no point into returning a transformer. If forward->solve() returns 0, maybe we could just nullify forward and when it is used later (only one place), returns an error. The same for reverse.

in reply to: ↑ 1   Changed 20 months ago by yavorr

Replying to rouault:

I got the problem because of an error in my source - the GCPs were added twice. I don't know the maths behind TPS and why duplicate points are a problem. In that case both solve() return 0.

In my case - i need to do some forward transformations and then the warp so it will be a problem if only one of the directions is available.

Note: See TracTickets for help on using tickets.