Skip to content
Permalink
Browse files

Don't crash raster shader with nan or inf values (fix #15444)

(cherry-picked from 34ebe12)
  • Loading branch information
nyalldawson committed Aug 17, 2016
1 parent 0feca4c commit a1f8a595ecdd6f51b40ebd34f9085155197a7d07
@@ -88,6 +88,9 @@ bool QgsColorRampShader::shade( double theValue, int* theReturnRedValue, int* th
{
return false;
}
if ( qIsNaN( theValue ) || qIsInf( theValue ) )
return false;

int colorRampItemListCount = mColorRampItemList.count();
int idx;
if ( !mLUTInitialized )
@@ -69,6 +69,7 @@ ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
ADD_PYTHON_TEST(PyQgsRangeWidgets test_qgsrangewidgets.py)
ADD_PYTHON_TEST(PyQgsRasterFileWriter test_qgsrasterfilewriter.py)
ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
ADD_PYTHON_TEST(PyQgsRasterColorRampShader test_qgsrastercolorrampshader.py)
ADD_PYTHON_TEST(PyQgsRectangle test_qgsrectangle.py)
ADD_PYTHON_TEST(PyQgsRelation test_qgsrelation.py)
ADD_PYTHON_TEST(PyQgsRelationManager test_qgsrelationmanager.py)
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsColorRampShader.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

__author__ = 'Nyall Dawson'
__date__ = '17/08/2016'
__copyright__ = 'Copyright 2016, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # NOQA


from qgis.PyQt.QtGui import QColor

from qgis.core import (QgsColorRampShader)
from qgis.testing import unittest


class TestQgsRasterColorRampShader(unittest.TestCase):

def testNan(self):
shader = QgsColorRampShader()

item1 = QgsColorRampShader.ColorRampItem(1, QColor(0, 0, 0))
item2 = QgsColorRampShader.ColorRampItem(2, QColor(255, 255, 255))
shader.setColorRampItemList([item1, item2])
self.assertFalse(shader.shade(float('NaN'))[0])
self.assertFalse(shader.shade(float("inf"))[0])

if __name__ == '__main__':
unittest.main()

0 comments on commit a1f8a59

Please sign in to comment.
You can’t perform that action at this time.