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.

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

mercurial