Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2013 The WebM 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 | #ifndef VP9_DECODER_VP9_READ_BIT_BUFFER_H_ |
michael@0 | 12 | #define VP9_DECODER_VP9_READ_BIT_BUFFER_H_ |
michael@0 | 13 | |
michael@0 | 14 | #include <limits.h> |
michael@0 | 15 | |
michael@0 | 16 | #include "vpx/vpx_integer.h" |
michael@0 | 17 | |
michael@0 | 18 | typedef void (*vp9_rb_error_handler)(void *data, size_t bit_offset); |
michael@0 | 19 | |
michael@0 | 20 | struct vp9_read_bit_buffer { |
michael@0 | 21 | const uint8_t *bit_buffer; |
michael@0 | 22 | const uint8_t *bit_buffer_end; |
michael@0 | 23 | size_t bit_offset; |
michael@0 | 24 | |
michael@0 | 25 | void *error_handler_data; |
michael@0 | 26 | vp9_rb_error_handler error_handler; |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | static size_t vp9_rb_bytes_read(struct vp9_read_bit_buffer *rb) { |
michael@0 | 30 | return rb->bit_offset / CHAR_BIT + (rb->bit_offset % CHAR_BIT > 0); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | static int vp9_rb_read_bit(struct vp9_read_bit_buffer *rb) { |
michael@0 | 34 | const size_t off = rb->bit_offset; |
michael@0 | 35 | const size_t p = off / CHAR_BIT; |
michael@0 | 36 | const int q = CHAR_BIT - 1 - (int)off % CHAR_BIT; |
michael@0 | 37 | if (rb->bit_buffer + p >= rb->bit_buffer_end) { |
michael@0 | 38 | rb->error_handler(rb->error_handler_data, rb->bit_offset); |
michael@0 | 39 | return 0; |
michael@0 | 40 | } else { |
michael@0 | 41 | const int bit = (rb->bit_buffer[p] & (1 << q)) >> q; |
michael@0 | 42 | rb->bit_offset = off + 1; |
michael@0 | 43 | return bit; |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | static int vp9_rb_read_literal(struct vp9_read_bit_buffer *rb, int bits) { |
michael@0 | 48 | int value = 0, bit; |
michael@0 | 49 | for (bit = bits - 1; bit >= 0; bit--) |
michael@0 | 50 | value |= vp9_rb_read_bit(rb) << bit; |
michael@0 | 51 | return value; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | static int vp9_rb_read_signed_literal(struct vp9_read_bit_buffer *rb, |
michael@0 | 55 | int bits) { |
michael@0 | 56 | const int value = vp9_rb_read_literal(rb, bits); |
michael@0 | 57 | return vp9_rb_read_bit(rb) ? -value : value; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | #endif // VP9_DECODER_VP9_READ_BIT_BUFFER_H_ |