An IndexError
indicates a bug or a logical error in the code.
In Python, lists and tuples have a certain length and their elements are indexed starting from 0
, counting up to the last index that
is still smaller than the length. When trying to access a list or tuple with an index outside of this range, an IndexError
will be raised
and the operation will fail.
Negative indices are supported. When using a negative index, it will be interpreted by computing the sum of the negative index and the list size.
The result is then used as the actual index for accessing the sequence. Thus, this sum must be non-negative and fit into the aforementioned range.
What is the potential impact?
Issues of this type interrupt the normal execution of a program, causing it to crash or putting it into an inconsistent state. Therefore, this
issue might impact the availability and reliability of your application, or even result in data loss.
If the computation of an index value is tied to user input data, this issue can potentially even be exploited by attackers to disrupt your
application.