From 33c98d8fffc726c1e178d2293d11fcd34f336006 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 29 May 2020 15:15:01 +0200 Subject: [PATCH] bmp/ico decoder: fail early for unsupported bit depths All the normal bit depths are supported, so no point in trying to go through the decoding code path for others. Avoids wide bitshift warning for claimed depths > 32. Change-Id: I61b72dbbf9558ca28db46f8168339f8174e56997 Reviewed-by: Paul Olav Tvete (cherry picked from commit 6a2224fd58414a78957104dd654f697c4b2eaa1d) Reviewed-by: Qt Cherry-pick Bot --- src/gui/image/qbmphandler.cpp | 6 +++++- src/plugins/imageformats/ico/qicohandler.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp index 7257853c3e5..396bb1964ef 100644 --- a/src/gui/image/qbmphandler.cpp +++ b/src/gui/image/qbmphandler.cpp @@ -262,9 +262,13 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, qint64 offset, depth = 8; format = QImage::Format_Indexed8; break; - default: + case 1: depth = 1; format = QImage::Format_Mono; + break; + default: + return false; + break; } if (depth != 32) { diff --git a/src/plugins/imageformats/ico/qicohandler.cpp b/src/plugins/imageformats/ico/qicohandler.cpp index 4908850cc50..701da0c06e1 100644 --- a/src/plugins/imageformats/ico/qicohandler.cpp +++ b/src/plugins/imageformats/ico/qicohandler.cpp @@ -491,8 +491,12 @@ QImage ICOReader::iconAt(int index) case 4: icoAttrib.depth = 8; break; - default: + case 1: icoAttrib.depth = 1; + break; + default: + return img; + break; } if (icoAttrib.depth == 32) // there's no colormap icoAttrib.ncolors = 0;