Commit fcacbfb2 authored by Frank Barchard's avatar Frank Barchard

validate scan EOI from end for better coverage

R=tpsiaki@google.com
BUG=libyuv:478

Review URL: https://codereview.chromium.org/1344623003 .
parent 67a9e302
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 1482
Version: 1483
License: BSD
License File: LICENSE
......
......@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 1482
#define LIBYUV_VERSION 1483
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
......@@ -42,6 +42,7 @@ static LIBYUV_BOOL ScanEOI(const uint8* sample, size_t sample_size) {
LIBYUV_BOOL ValidateJpeg(const uint8* sample, size_t sample_size) {
// Maximum size that ValidateJpeg will consider valid.
const size_t kMaxJpegSize = 0x7fffffffull;
const size_t kBackSearchSize = 1024;
if (sample_size < 64 || sample_size > kMaxJpegSize || !sample) {
// ERROR: Invalid jpeg size: sample_size
return LIBYUV_FALSE;
......@@ -50,6 +51,15 @@ LIBYUV_BOOL ValidateJpeg(const uint8* sample, size_t sample_size) {
// ERROR: Invalid jpeg initial start code
return LIBYUV_FALSE;
}
// Look for the End Of Image (EOI) marker near the end of the buffer.
if (sample_size > kBackSearchSize) {
if (ScanEOI(sample + sample_size - kBackSearchSize, kBackSearchSize)) {
return LIBYUV_TRUE; // Success: Valid jpeg.
}
// Reduce search size for forward search.
sample_size = sample_size - kBackSearchSize + 1;
}
// Step over SOI marker and scan for EOI.
return ScanEOI(sample + 2, sample_size - 2);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment