diff --git a/libs/gfx/source/pixmap.cpp b/libs/gfx/source/pixmap.cpp index 47b5fc81..48a033f1 100644 --- a/libs/gfx/source/pixmap.cpp +++ b/libs/gfx/source/pixmap.cpp @@ -34,12 +34,16 @@ namespace psemek::gfx fail("P1 format is not supported"); std::getline(is, line); + if (!is) + fail("stream error"); std::istringstream sline(line); std::size_t width, height; pixmap_monochrome pixmap; sline >> width >> height; + if (!sline) + fail("stream error"); pixmap.resize({width, height}); @@ -89,6 +93,8 @@ namespace psemek::gfx fail("unknown format " + line); std::getline(is, line); + if (!is) + fail("stream error"); std::istringstream sline(line); std::size_t width, height; @@ -96,10 +102,17 @@ namespace psemek::gfx pixmap_monochrome pixmap; sline >> width >> height; + if (!sline) + fail("stream error"); std::getline(is, line); + if (!is) + fail("stream error"); + sline.clear(); sline.str(line); sline >> max; + if (!sline) + fail("stream error"); if (max != 255) fail("max value " + std::to_string(max) + " is not supported"); @@ -117,7 +130,7 @@ namespace psemek::gfx return pixmap; } - pixmap_rgb load_ppm(std::istream & is) + pixmap_rgb read_ppm(std::istream & is) { auto fail = [](std::string str) { @@ -141,6 +154,8 @@ namespace psemek::gfx fail("unknown format " + line); std::getline(is, line); + if (!is) + fail("stream error"); std::istringstream sline(line); std::size_t width, height; @@ -149,9 +164,17 @@ namespace psemek::gfx sline >> width >> height; + if (!sline) + fail("stream error"); + std::getline(is, line); + if (!is) + fail("stream error"); + sline.clear(); sline.str(line); sline >> max; + if (!sline) + fail("stream error"); if (max != 255) fail("max value " + std::to_string(max) + " is not supported");