if (inIco) {
height /= 2;
}
- if (width <= 0 || height <= 0) {
- // TODO: Decide if we want to disable really large bmps as well.
- // https://code.google.com/p/skia/issues/detail?id=3617
+
+ // Arbitrary maximum. Matches Chromium.
+ constexpr int kMaxDim = 1 << 16;
+ if (width <= 0 || height <= 0 || width >= kMaxDim || height >= kMaxDim) {
SkCodecPrintf("Error: invalid bitmap dimensions.\n");
return false;
}
#include "SkFrontBufferedStream.h"
#include "SkImageEncoder.h"
#include "SkMD5.h"
+#include "SkOSPath.h"
#include "SkPngChunkReader.h"
#include "SkRandom.h"
#include "SkStream.h"
}
DEF_TEST(Codec_InvalidBmp, r) {
- // This file reports a header size that crashes when we try to read this
- // much directly from a file using SkFILEStream.
- SkString path = GetResourcePath("invalid_images/b33651913.bmp");
- std::unique_ptr<SkFILEStream> stream(new SkFILEStream(path.c_str()));
- if (!stream->isValid()) {
- ERRORF(r, "no stream");
- return;
- }
+ // These files report values that have caused problems with SkFILEStreams.
+ // They are invalid, and should not create SkCodecs.
+ for (auto* bmp : { "b33651913.bmp", "b34778578.bmp" } ) {
+ SkString path = SkOSPath::Join("invalid_images", bmp);
+ path = GetResourcePath(path.c_str());
+ std::unique_ptr<SkFILEStream> stream(new SkFILEStream(path.c_str()));
+ if (!stream->isValid()) {
+ return;
+ }
- std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
- // This file is invalid, but more importantly, we did not crash before
- // reaching here.
- REPORTER_ASSERT(r, !codec);
+ std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+ REPORTER_ASSERT(r, !codec);
+ }
}
DEF_TEST(Codec_InvalidRLEBmp, r) {