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

Unified Diff: Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

Issue 1039503003: Add helper to validate JPEG decode subsampling factors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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: Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
diff --git a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
index 87923f6ef115839345b8e5b49ddfe3ad0c117ade..a244c936b78683a5cd049947106e37ce9377d05c 100644
--- a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
+++ b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
@@ -299,6 +299,21 @@ static yuv_subsampling yuvSubsampling(const jpeg_decompress_struct& info)
return YUV_UNKNOWN;
}
+bool validateSubsampling(const jpeg_decompress_struct* cinfo)
+{
+ ASSERT(cinfo->num_components);
+
+ jpeg_component_info* component = cinfo->comp_info;
+ for (int c = 0; c < cinfo->num_components; ++c, ++component) {
+ if (component->h_samp_factor == 3)
+ component->h_samp_factor = 1;
+ if (component->v_samp_factor == 3)
+ component->v_samp_factor = 1;
+ }
+
+ return true;
+}
+
class JPEGImageReader {
WTF_MAKE_FAST_ALLOCATED(JPEGImageReader);
public:
@@ -396,6 +411,7 @@ public:
return m_decoder->setFailed();
J_COLOR_SPACE overrideColorSpace = JCS_UNKNOWN;
+
switch (m_state) {
case JPEG_HEADER:
// Read file parameters with jpeg_read_header().
@@ -432,6 +448,9 @@ public:
return m_decoder->setFailed();
}
+ if (!validateSubsampling(&m_info))
+ return m_decoder->setFailed();
+
m_state = JPEG_START_DECOMPRESS;
// We can fill in the size now that the header is available.
« 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