Skip to content
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

DM-31027: Fix buffer overrun in getMaskPropagationThreshold and add tests. #598

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/math/Statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ std::shared_ptr<std::vector<typename ImageT::Pixel> > makeVectorCopy(ImageT cons

double StatisticsControl::getMaskPropagationThreshold(int bit) const {
int oldSize = _maskPropagationThresholds.size();
if (oldSize < bit) {
if (oldSize <= bit) {
return 1.0;
}
return _maskPropagationThresholds[bit];
Expand Down
57 changes: 57 additions & 0 deletions tests/test_maskPropagationThreshold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This file is part of afw.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Tests for statsCtrl mask propagation thresholds."""
import unittest

import lsst.utils.tests
import lsst.afw.math as afwMath


class PropagationThresholdTestCase(lsst.utils.tests.TestCase):
"""Testing for propagation thresholds."""
def testEmpty(self):
"""Test retrieving an empty threshold."""
statsCtrl = afwMath.StatisticsControl()
self.assertEqual(statsCtrl.getMaskPropagationThreshold(0), 1.0)

def testSetSingle(self):
"""Test setting and retrieving a single threshold."""
statsCtrl = afwMath.StatisticsControl()
statsCtrl.setMaskPropagationThreshold(1, 0.1)

for bit in range(32):
if bit == 1:
self.assertEqual(statsCtrl.getMaskPropagationThreshold(bit), 0.1)
else:
self.assertEqual(statsCtrl.getMaskPropagationThreshold(bit), 1.0)


class TestMemory(lsst.utils.tests.MemoryTestCase):
pass


def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()