mirror of
https://github.com/Evolution-X/external_piex
synced 2026-02-01 07:35:29 +00:00
Fix heap buffer overflows in GetFullCropDimension in tiff_parser.cc
Author: timurrrr@google.com Bug: 73646839 Bug: 62307613 Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6347
This commit is contained in:
committed by
Leon Scroggins
parent
cc441e44be
commit
f7fc905cff
@@ -596,23 +596,41 @@ bool GetFullDimension32(const TiffDirectory& tiff_directory,
|
|||||||
|
|
||||||
bool GetFullCropDimension(const tiff_directory::TiffDirectory& tiff_directory,
|
bool GetFullCropDimension(const tiff_directory::TiffDirectory& tiff_directory,
|
||||||
std::uint32_t* width, std::uint32_t* height) {
|
std::uint32_t* width, std::uint32_t* height) {
|
||||||
if (tiff_directory.Has(kExifTagDefaultCropSize)) {
|
if (!tiff_directory.Has(kExifTagDefaultCropSize)) {
|
||||||
std::vector<std::uint32_t> crop(2);
|
// This doesn't look right to return true here, as we have not written
|
||||||
std::vector<Rational> crop_rational(2);
|
// anything to *width and *height. However, changing the return value here
|
||||||
if (tiff_directory.Get(kExifTagDefaultCropSize, &crop)) {
|
// causes a whole bunch of tests to fail.
|
||||||
|
// TODO(timurrrr): Return false and fix the tests.
|
||||||
|
// In fact, this whole if() seems to be not needed,
|
||||||
|
// as tiff_directory(kExifTagDefaultCropSize) will return false below.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::uint32_t> crop(2);
|
||||||
|
if (tiff_directory.Get(kExifTagDefaultCropSize, &crop)) {
|
||||||
|
if (crop.size() == 2 && crop[0] > 0 && crop[1] > 0) {
|
||||||
*width = crop[0];
|
*width = crop[0];
|
||||||
*height = crop[1];
|
*height = crop[1];
|
||||||
} else if (tiff_directory.Get(kExifTagDefaultCropSize, &crop_rational) &&
|
return true;
|
||||||
crop_rational[0].denominator != 0 &&
|
|
||||||
crop_rational[1].denominator != 0) {
|
|
||||||
*width = crop_rational[0].numerator / crop_rational[0].denominator;
|
|
||||||
*height = crop_rational[1].numerator / crop_rational[1].denominator;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
std::vector<Rational> crop_rational(2);
|
||||||
|
if (tiff_directory.Get(kExifTagDefaultCropSize, &crop_rational)) {
|
||||||
|
if (crop_rational.size() == 2 && crop_rational[0].numerator > 0 &&
|
||||||
|
crop_rational[0].denominator > 0 && crop_rational[1].numerator > 0 &&
|
||||||
|
crop_rational[1].denominator > 0) {
|
||||||
|
*width = crop_rational[0].numerator / crop_rational[0].denominator;
|
||||||
|
*height = crop_rational[1].numerator / crop_rational[1].denominator;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TiffParser::TiffParser(StreamInterface* stream) : stream_(stream) {}
|
TiffParser::TiffParser(StreamInterface* stream) : stream_(stream) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user