Skip to content

Unsigned integer underflow in met data interpolation if out of met data range #112

Description

@lrobion

In Util/MetFunction.cpp:358 the function linInterpMetData declares the index of the met data cell below the target interpolation point as an unsigned int std::size_t idx_x1;.

Later we can assign it i_Z - 1; which can be negative if i_Z the nearest cell to the target point is index 0. This means that the target point is outside the met data and we should throw an error, but because idx_x1 is unsigned it wraps to whatever is the max value for that type and the subsequent check never catches the out of bounds:

if(idx_x1 < 0) { 
    throw std::range_error("Input flight altitude out of range of met. data!"); 
}

I introduced this bug when I was cleaning compiler warnings on int to std::size_t conversions for vector indexing in #24. I don't think anyone encountered this because most people pass the weather column from the surface to a bit above cruise but this is incorrect.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions