Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: src/codec/SkRawCodec.cpp

Issue 1782063002: Add a quick check to the TIFF header of DNG image (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkRawCodec.cpp
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp
index 609b0aef02b42761044c29d4085555cbb6975e35..208bd8952d1be3186f6acb711518296e0833c7fc 100644
--- a/src/codec/SkRawCodec.cpp
+++ b/src/codec/SkRawCodec.cpp
@@ -215,6 +215,8 @@ public:
}
private:
+ // Most of valid RAW images will not be larger than 100MB. This limit is helpful to avoid
+ // streaming too large data chunk. We can always adjust the limit here if we need.
const size_t kMaxStreamSize = 100 * 1024 * 1024; // 100MB
typedef SkDynamicMemoryWStream INHERITED;
@@ -445,6 +447,10 @@ public:
*/
static SkDngImage* NewFromStream(SkRawStream* stream) {
SkAutoTDelete<SkDngImage> dngImage(new SkDngImage(stream));
+ if (!dngImage->isTiffHeaderValid()) {
msarett 2016/03/10 13:51:56 Just to make sure I understand: All dngs should h
yujieqin 2016/03/10 13:56:03 Yes, DNG image is basically an extended TIFF. It s
+ return nullptr;
+ }
+
if (!dngImage->initFromPiex()) {
if (!dngImage->readDng()) {
return nullptr;
@@ -522,6 +528,20 @@ public:
}
private:
+ // Quick check if the image contains a valid TIFF header as requested by DNG format.
+ bool isTiffHeaderValid() const {
+ const size_t kHeaderSize = 4;
+ SkAutoSTMalloc<kHeaderSize, unsigned char> header(kHeaderSize);
+ if (!fStream->read(header.get(), 0 /* offset */, kHeaderSize)) {
+ return false;
+ }
+
+ // Check if the header is valid (endian info and magic number "42").
+ return
+ (header[0] == 0x49 && header[1] == 0x49 && header[2] == 0x2A && header[3] == 0x00) ||
+ (header[0] == 0x4D && header[1] == 0x4D && header[2] == 0x00 && header[3] == 0x2A);
+ }
+
void init(const int width, const int height, const dng_point& cfaPatternSize) {
fImageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kOpaque_SkAlphaType);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698