aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib
diff options
context:
space:
mode:
authorGravatar Mihai Maruseac <mihaimaruseac@google.com>2018-09-24 09:35:58 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-24 09:40:32 -0700
commit4cf68d9b869c0cb1efe9865e764c997649b7fbc0 (patch)
treee6f0e028fd4fb97d9f79b91adbbb571c04ecb14d /tensorflow/core/lib
parentaf959c2f25e29ff1a76d8ad2a8100780e1bca8cf (diff)
Check for too large jpeg images before decompressing.
PiperOrigin-RevId: 214279868
Diffstat (limited to 'tensorflow/core/lib')
-rw-r--r--tensorflow/core/lib/jpeg/jpeg_mem.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/tensorflow/core/lib/jpeg/jpeg_mem.cc b/tensorflow/core/lib/jpeg/jpeg_mem.cc
index 50ed8bdb3b..f7a359eb5b 100644
--- a/tensorflow/core/lib/jpeg/jpeg_mem.cc
+++ b/tensorflow/core/lib/jpeg/jpeg_mem.cc
@@ -152,7 +152,9 @@ uint8* UncompressLow(const void* srcdata, FewerArgsForCompiler* argball) {
cinfo.scale_denom = ratio;
cinfo.dct_method = flags.dct_method;
- jpeg_start_decompress(&cinfo);
+ // Determine the output image size before attempting decompress to prevent
+ // OOM'ing doing the decompress
+ jpeg_calc_output_dimensions(&cinfo);
int64 total_size = static_cast<int64>(cinfo.output_height) *
static_cast<int64>(cinfo.output_width);
@@ -170,6 +172,8 @@ uint8* UncompressLow(const void* srcdata, FewerArgsForCompiler* argball) {
return nullptr;
}
+ jpeg_start_decompress(&cinfo);
+
JDIMENSION target_output_width = cinfo.output_width;
JDIMENSION target_output_height = cinfo.output_height;
JDIMENSION skipped_scanlines = 0;