From 09cfb2bbd61448da73a65cdf8eac3594290522bf Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Mon, 1 Jul 2019 15:21:39 -0700 Subject: [PATCH] Update to r1732 for more robust jpeg Includes a rounding change for neon. BUG=b/135532289 Change-Id: I36ffb57b55db6c64804ad169def865be1ac6d66e Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/1684439 Commit-Queue: Frank Barchard Reviewed-by: Chong Zhang --- .gitignore | 1 + README.chromium | 2 +- include/libyuv/version.h | 2 +- source/mjpeg_decoder.cc | 13 +++++++++++-- source/mjpeg_validate.cc | 3 ++- source/row_neon64.cc | 4 ++-- unit_test/convert_test.cc | 6 +++++- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index cdd60468e..7095d4170 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ pin-log.txt /native_client /net /out +/source/out /sde-avx-sse-transition-out.txt /testing /third_party diff --git a/README.chromium b/README.chromium index 786fcd3b0..bddc20238 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1731 +Version: 1732 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 6ab8a6790..741ef34df 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1731 +#define LIBYUV_VERSION 1732 #endif // INCLUDE_LIBYUV_VERSION_H_ diff --git a/source/mjpeg_decoder.cc b/source/mjpeg_decoder.cc index eaf253013..5c5e5eadf 100644 --- a/source/mjpeg_decoder.cc +++ b/source/mjpeg_decoder.cc @@ -25,7 +25,8 @@ #endif #endif -struct FILE; // For jpeglib.h. + +#include // For jpeglib.h. // C++ build requires extern C for jpeg internals. #ifdef __cplusplus @@ -427,7 +428,15 @@ boolean fill_input_buffer(j_decompress_ptr cinfo) { } void skip_input_data(j_decompress_ptr cinfo, long num_bytes) { // NOLINT - cinfo->src->next_input_byte += num_bytes; + jpeg_source_mgr* src = cinfo->src; + size_t bytes = static_cast(num_bytes); + if(bytes > src->bytes_in_buffer) { + src->next_input_byte = nullptr; + src->bytes_in_buffer = 0; + } else { + src->next_input_byte += bytes; + src->bytes_in_buffer -= bytes; + } } void term_source(j_decompress_ptr cinfo) { diff --git a/source/mjpeg_validate.cc b/source/mjpeg_validate.cc index d22b62df0..ba0a03ab9 100644 --- a/source/mjpeg_validate.cc +++ b/source/mjpeg_validate.cc @@ -47,7 +47,8 @@ LIBYUV_BOOL ValidateJpeg(const uint8_t* src_mjpg, size_t src_size_mjpg) { // ERROR: Invalid jpeg size: src_size_mjpg return LIBYUV_FALSE; } - if (src_mjpg[0] != 0xff || src_mjpg[1] != 0xd8) { // SOI marker + // SOI marker + if (src_mjpg[0] != 0xff || src_mjpg[1] != 0xd8 || src_mjpg[2] != 0xff) { // ERROR: Invalid jpeg initial start code return LIBYUV_FALSE; } diff --git a/source/row_neon64.cc b/source/row_neon64.cc index 449c9f394..f5cbb4701 100644 --- a/source/row_neon64.cc +++ b/source/row_neon64.cc @@ -2986,8 +2986,8 @@ void FloatDivToByteRow_NEON(const float* src_weights, "fdiv v1.4s, v3.4s, v1.4s \n" // values / weights "fdiv v2.4s, v4.4s, v2.4s \n" - "fcvtzu v1.4s, v1.4s \n" // float to int - "fcvtzu v2.4s, v2.4s \n" // float to int + "fcvtas v1.4s, v1.4s \n" // float to int + "fcvtas v2.4s, v2.4s \n" // float to int "uqxtn v1.4h, v1.4s \n" // 8 shorts "uqxtn2 v1.8h, v2.4s \n" "uqxtn v1.8b, v1.8h \n" // 8 bytes diff --git a/unit_test/convert_test.cc b/unit_test/convert_test.cc index 657c66565..32a4cd1ca 100644 --- a/unit_test/convert_test.cc +++ b/unit_test/convert_test.cc @@ -1390,6 +1390,7 @@ TEST_F(LibYUVConvertTest, ValidateJpeg) { // EOI, SOI. Expect pass. orig_pixels[0] = 0xff; orig_pixels[1] = 0xd8; // SOI. + orig_pixels[2] = 0xff; orig_pixels[kSize - kOff + 0] = 0xff; orig_pixels[kSize - kOff + 1] = 0xd9; // EOI. for (int times = 0; times < benchmark_iterations_; ++times) { @@ -1416,6 +1417,7 @@ TEST_F(LibYUVConvertTest, ValidateJpegLarge) { // EOI, SOI. Expect pass. orig_pixels[0] = 0xff; orig_pixels[1] = 0xd8; // SOI. + orig_pixels[2] = 0xff; orig_pixels[kSize - kOff + 0] = 0xff; orig_pixels[kSize - kOff + 1] = 0xd9; // EOI. for (int times = 0; times < benchmark_iterations_; ++times) { @@ -1449,6 +1451,7 @@ TEST_F(LibYUVConvertTest, InvalidateJpeg) { // SOI but no EOI. Expect fail. orig_pixels[0] = 0xff; orig_pixels[1] = 0xd8; // SOI. + orig_pixels[2] = 0xff; for (int times = 0; times < benchmark_iterations_; ++times) { EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize)); } @@ -1466,13 +1469,14 @@ TEST_F(LibYUVConvertTest, InvalidateJpeg) { TEST_F(LibYUVConvertTest, FuzzJpeg) { // SOI but no EOI. Expect fail. for (int times = 0; times < benchmark_iterations_; ++times) { - const int kSize = fastrand() % 5000 + 2; + const int kSize = fastrand() % 5000 + 3; align_buffer_page_end(orig_pixels, kSize); MemRandomize(orig_pixels, kSize); // Add SOI so frame will be scanned. orig_pixels[0] = 0xff; orig_pixels[1] = 0xd8; // SOI. + orig_pixels[2] = 0xff; orig_pixels[kSize - 1] = 0xff; ValidateJpeg(orig_pixels, kSize); // Failure normally expected.