media/libyuv/source/mjpeg_validate.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright 2012 The LibYuv Project Authors. All rights reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11 #include "libyuv/mjpeg_decoder.h"
michael@0 12
michael@0 13 #ifdef __cplusplus
michael@0 14 namespace libyuv {
michael@0 15 extern "C" {
michael@0 16 #endif
michael@0 17
michael@0 18 // Helper function to validate the jpeg appears intact.
michael@0 19 // TODO(fbarchard): Optimize case where SOI is found but EOI is not.
michael@0 20 LIBYUV_BOOL ValidateJpeg(const uint8* sample, size_t sample_size) {
michael@0 21 size_t i;
michael@0 22 if (sample_size < 64) {
michael@0 23 // ERROR: Invalid jpeg size: sample_size
michael@0 24 return LIBYUV_FALSE;
michael@0 25 }
michael@0 26 if (sample[0] != 0xff || sample[1] != 0xd8) { // Start Of Image
michael@0 27 // ERROR: Invalid jpeg initial start code
michael@0 28 return LIBYUV_FALSE;
michael@0 29 }
michael@0 30 for (i = sample_size - 2; i > 1;) {
michael@0 31 if (sample[i] != 0xd9) {
michael@0 32 if (sample[i] == 0xff && sample[i + 1] == 0xd9) { // End Of Image
michael@0 33 return LIBYUV_TRUE; // Success: Valid jpeg.
michael@0 34 }
michael@0 35 --i;
michael@0 36 }
michael@0 37 --i;
michael@0 38 }
michael@0 39 // ERROR: Invalid jpeg end code not found. Size sample_size
michael@0 40 return LIBYUV_FALSE;
michael@0 41 }
michael@0 42
michael@0 43 #ifdef __cplusplus
michael@0 44 } // extern "C"
michael@0 45 } // namespace libyuv
michael@0 46 #endif
michael@0 47

mercurial