diff --git a/.travis.yml b/.travis.yml index a7bab3b4..7dddabd1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ compiler: os: - linux - osx -script: sh autogen.sh && ./configure --enable-custom-allocator && make -j4 && make check && make clean && ./configure --disable-advanced-jpeg-features --enable-custom-allocator && make -j4 && make check && make clean && CXXFLAGS="-O2 -DALLOW_3_OR_4_SCALING_FACTOR -DALLOW_FOUR_COLORS" ./configure && make -j4 && make check && make clean && ./configure --disable-vectorization --enable-custom-allocator && make -j4 && make check && make clean && ./configure --enable-ans-experimental && make -j4 && make check +script: sh autogen.sh && ./configure CXXFLAGS="-O2 -g -mssse3" --enable-custom-allocator && make liblocalzlib.a && make -j4 && make check && make clean && ./configure CXXFLAGS="-O2 -g -mssse3" --disable-advanced-jpeg-features --enable-custom-allocator && make liblocalzlib.a && make -j4 && make check && make clean && CXXFLAGS="-O2 -mssse3 -DALLOW_3_OR_4_SCALING_FACTOR -DALLOW_FOUR_COLORS" ./configure CXXFLAGS="-O2 -mssse3 -g" && make liblocalzlib.a && make -j4 && make check && make clean && ./configure CXXFLAGS="-O2 -mssse3 -g" --disable-vectorization --enable-custom-allocator && make liblocalzlib.a && make -j4 && make check && make clean && ./configure CXXFLAGS="-O2 -mssse3 -g" --enable-ans-experimental && make liblocalzlib.a && make -j4 && make check diff --git a/Makefile.am b/Makefile.am index c2d07a33..1b5f615b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -360,9 +360,9 @@ test_suite_test_trailing_rst_SOURCES = test_suite/test_harness.cc test_suite_test_trailing_rst_CXXFLAGS = $(AM_CXXFLAGS) -DUSE_LEPTON -DTEST_FILE=trailingrst -DTEST_FILE0=trailingrst2 test_suite_test_trailing_rst_LDADD = libtestdriver.a -lpthread -TESTS = test_suite/test_recode_memory_bound test_suite/test_invariants test_suite/test_baseline_ujg test_suite/test_baseline test_suite/test_misc test_suite/test_iphone test_suite/test_phone_outdoor test_suite/test_truncate test_suite/test_single_row_truncate test_suite/test_android_lowmem test_suite/test_SLR test_suite/test_progressive_ujg test_suite/test_progressive_disallowed test_suite/test_progressive test_suite/test_arithmetic_failfast test_suite/test_hq test_suite/forktester.py test_suite/sockettester.py src/lepton/test_custom_table.sh test_suite/test_baseline_unjailed test_suite/test_baseline_unjailed_thread test_suite/test_baseline_unjailed_decode test_suite/test_baseline_unjailed_decode_thread test_suite/test_seccomp_encode_main test_suite/test_seccomp_encode_thread test_suite/test_seccomp_decode_main test_suite/test_seccomp_decode_thread test_suite/test_truncate_lowmem test_suite/test_nofsync test_suite/test_colorswap test_suite/test_odd_rst test_suite/test_trailing_header test_suite/test_trailing_rst test_suite/test_legacy.sh test_suite/test_roundtrip.sh test_suite/test_embedded.sh test_suite/test_16threads.sh test_suite/test_future_compat.sh test_suite/test_gray2sf test_suite/test_2nd_block.sh test_suite/test_3rd_block.sh test_suite/test_last_block.sh test_suite/test_truncated_zero_run test_suite/test_bad_zero_run test_suite/test_concat.sh test_suite/test_permissive.sh +TESTS = test_suite/test_recode_memory_bound test_suite/test_invariants test_suite/test_baseline_ujg test_suite/test_baseline test_suite/test_misc test_suite/test_iphone test_suite/test_phone_outdoor test_suite/test_truncate test_suite/test_single_row_truncate test_suite/test_android_lowmem test_suite/test_SLR test_suite/test_progressive_ujg test_suite/test_progressive_disallowed test_suite/test_progressive test_suite/test_arithmetic_failfast test_suite/test_hq test_suite/forktester.py test_suite/sockettester.py src/lepton/test_custom_table.sh test_suite/test_baseline_unjailed test_suite/test_baseline_unjailed_thread test_suite/test_baseline_unjailed_decode test_suite/test_baseline_unjailed_decode_thread test_suite/test_seccomp_encode_main test_suite/test_seccomp_encode_thread test_suite/test_seccomp_decode_main test_suite/test_seccomp_decode_thread test_suite/test_truncate_lowmem test_suite/test_nofsync test_suite/test_colorswap test_suite/test_odd_rst test_suite/test_trailing_header test_suite/test_trailing_rst test_suite/test_legacy.sh test_suite/test_roundtrip.sh test_suite/test_embedded.sh test_suite/test_16threads.sh test_suite/test_future_compat.sh test_suite/test_gray2sf test_suite/test_2nd_block.sh test_suite/test_3rd_block.sh test_suite/test_last_block.sh test_suite/test_truncated_zero_run test_suite/test_bad_zero_run test_suite/test_concat.sh test_suite/test_permissive.sh test_suite/test_clobber.sh -dist_check_SCRIPTS = test_suite/test_recode_memory_bound test_suite/test_invariants test_suite/test_baseline_ujg test_suite/test_baseline test_suite/test_misc test_suite/test_iphone test_suite/test_phone_outdoor test_suite/test_truncate test_suite/test_single_row_truncate test_suite/test_android_lowmem test_suite/test_SLR test_suite/test_progressive_ujg test_suite/test_progressive_disallowed test_suite/test_progressive test_suite/test_arithmetic_failfast test_suite/test_hq test_suite/test_baseline_unjailed test_suite/test_baseline_unjailed_thread test_suite/test_baseline_unjailed_decode test_suite/test_baseline_unjailed_decode_thread test_suite/test_seccomp_encode_main test_suite/test_seccomp_encode_thread test_suite/test_seccomp_decode_main test_suite/test_seccomp_decode_thread test_suite/test_truncate_lowmem test_suite/test_nofsync test_suite/test_colorswap test_suite/test_odd_rst test_suite/test_trailing_header test_suite/test_trailing_rst test_suite/test_legacy.sh test_suite/test_roundtrip.sh test_suite/test_embedded.sh test_suite/test_16threads.sh test_suite/test_future_compat.sh test_suite/test_gray2sf test_suite/test_2nd_block.sh test_suite/test_3rd_block.sh test_suite/test_last_block.sh test_suite/test_truncated_zero_run test_suite/test_bad_zero_run test_suite/test_concat.sh test_suite/test_permissive.sh +dist_check_SCRIPTS = test_suite/test_recode_memory_bound test_suite/test_invariants test_suite/test_baseline_ujg test_suite/test_baseline test_suite/test_misc test_suite/test_iphone test_suite/test_phone_outdoor test_suite/test_truncate test_suite/test_single_row_truncate test_suite/test_android_lowmem test_suite/test_SLR test_suite/test_progressive_ujg test_suite/test_progressive_disallowed test_suite/test_progressive test_suite/test_arithmetic_failfast test_suite/test_hq test_suite/test_baseline_unjailed test_suite/test_baseline_unjailed_thread test_suite/test_baseline_unjailed_decode test_suite/test_baseline_unjailed_decode_thread test_suite/test_seccomp_encode_main test_suite/test_seccomp_encode_thread test_suite/test_seccomp_decode_main test_suite/test_seccomp_decode_thread test_suite/test_truncate_lowmem test_suite/test_nofsync test_suite/test_colorswap test_suite/test_odd_rst test_suite/test_trailing_header test_suite/test_trailing_rst test_suite/test_legacy.sh test_suite/test_roundtrip.sh test_suite/test_embedded.sh test_suite/test_16threads.sh test_suite/test_future_compat.sh test_suite/test_gray2sf test_suite/test_2nd_block.sh test_suite/test_3rd_block.sh test_suite/test_last_block.sh test_suite/test_truncated_zero_run test_suite/test_bad_zero_run test_suite/test_concat.sh test_suite/test_permissive.sh test_suite/test_clobber.sh test: $(MAKE) check diff --git a/src/ans/rans64.hh b/src/ans/rans64.hh index 17a2e79e..a15a45cd 100644 --- a/src/ans/rans64.hh +++ b/src/ans/rans64.hh @@ -34,7 +34,8 @@ static inline uint64_t Rans64MulHi(uint64_t a, uint64_t b) { - return __umulh(a, b); +// return __umulh(a, b); + abort(); } #elif defined(__GNUC__) diff --git a/src/io/Allocator.hh b/src/io/Allocator.hh index f9d0d173..51d0cbf8 100644 --- a/src/io/Allocator.hh +++ b/src/io/Allocator.hh @@ -26,8 +26,8 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SIRIKATA_JPEG_ARHC_ALLOCATOR_HPP_ -#define _SIRIKATA_JPEG_ARHC_ALLOCATOR_HPP_ +#ifndef SIRIKATA_JPEG_ARHC_ALLOCATOR_HPP_ +#define SIRIKATA_JPEG_ARHC_ALLOCATOR_HPP_ #include #include "DecoderPlatform.hh" namespace Sirikata { diff --git a/src/io/DecoderPlatform.hh b/src/io/DecoderPlatform.hh index 5e2bfbc0..093ed726 100644 --- a/src/io/DecoderPlatform.hh +++ b/src/io/DecoderPlatform.hh @@ -56,8 +56,8 @@ typedef uint8_t byte; typedef int8_t int8; } -#ifndef _DECODER_PLATFORM_HH_ -#define _DECODER_PLATFORM_HH_ +#ifndef DECODER_PLATFORM_HH_ +#define DECODER_PLATFORM_HH_ #ifdef _WIN32 #include inline int write(int fd, const void*data, unsigned int length) { diff --git a/src/io/Error.hh b/src/io/Error.hh index 03f730ef..ead31e6d 100644 --- a/src/io/Error.hh +++ b/src/io/Error.hh @@ -26,8 +26,8 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SIRIKATA_JPEG_ARHC_ERROR_HPP_ -#define _SIRIKATA_JPEG_ARHC_ERROR_HPP_ +#ifndef SIRIKATA_JPEG_ARHC_ERROR_HPP_ +#define SIRIKATA_JPEG_ARHC_ERROR_HPP_ namespace Sirikata { diff --git a/src/io/MemMgrAllocator.hh b/src/io/MemMgrAllocator.hh index d5c4aac9..a0226c70 100644 --- a/src/io/MemMgrAllocator.hh +++ b/src/io/MemMgrAllocator.hh @@ -33,8 +33,8 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _MEM_MGR_ALLOCATOR_HH_ -#define _MEM_MGR_ALLOCATOR_HH_ +#ifndef MEM_MGR_ALLOCATOR_HH_ +#define MEM_MGR_ALLOCATOR_HH_ #include "DecoderPlatform.hh" namespace Sirikata { diff --git a/src/io/MuxReader.hh b/src/io/MuxReader.hh index bb2c19f0..a28d5b3f 100644 --- a/src/io/MuxReader.hh +++ b/src/io/MuxReader.hh @@ -26,8 +26,8 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SIRIKATA_MUX_READER_HPP_ -#define _SIRIKATA_MUX_READER_HPP_ +#ifndef SIRIKATA_MUX_READER_HPP_ +#define SIRIKATA_MUX_READER_HPP_ #include #include #include "Allocator.hh" diff --git a/src/io/Reader.hh b/src/io/Reader.hh index c38e729c..4e359fab 100644 --- a/src/io/Reader.hh +++ b/src/io/Reader.hh @@ -26,8 +26,8 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SIRIKATA_READER_HPP_ -#define _SIRIKATA_READER_HPP_ +#ifndef SIRIKATA_READER_HPP_ +#define SIRIKATA_READER_HPP_ #include "Allocator.hh" #include "Error.hh" diff --git a/src/io/ZlibCompression.cc b/src/io/ZlibCompression.cc index e3021a39..cfd8e7e5 100644 --- a/src/io/ZlibCompression.cc +++ b/src/io/ZlibCompression.cc @@ -114,7 +114,7 @@ std::pair >, } if (strm.avail_out == 0) { retval_size += avail_bytes - strm.avail_out; - if (retval.first.size() == max_file_size) { + if (retval.first.size() >= max_file_size) { retval.second = JpegError::errShortHuffmanData(); break; } diff --git a/src/io/ioutil.cc b/src/io/ioutil.cc index a9111d5a..803fbcbf 100644 --- a/src/io/ioutil.cc +++ b/src/io/ioutil.cc @@ -198,7 +198,7 @@ Sirikata::Array1d send_and_md5_result(const uint8_t *data, MD5_Final(&retval[0], &context); return retval; } -void md5_and_copy_to_tee(int copy_to_input_tee, int input_tee, MD5_CTX *context, size_t *input_size, size_t start_byte, size_t end_byte, bool close_input, bool is_socket) { +void md5_and_copy_to_tee(int copy_to_input_tee, int input_tee, MD5_CTX *context, size_t *input_size, size_t start_byte, size_t end_byte, bool close_input, bool is_socket, std::vector*byte_return) { unsigned char buffer[65536]; while (true) { size_t max_to_read = sizeof(buffer); @@ -220,10 +220,16 @@ void md5_and_copy_to_tee(int copy_to_input_tee, int input_tee, MD5_CTX *context, if (*input_size + del > start_byte) { if (*input_size >= start_byte) { MD5_Update(context, &buffer[0], del); + if (byte_return) { + byte_return->insert(byte_return->end(), &buffer[0], &buffer[0] + del); + } } else { size_t offset = (start_byte - *input_size); MD5_Update(context, &buffer[offset], del - offset); - } + if (byte_return) { + byte_return->insert(byte_return->end(), &buffer[offset], &buffer[offset] + (del-offset)); + } + } } { // write all to the subprocess size_t cursor = 0; @@ -242,8 +248,14 @@ void md5_and_copy_to_tee(int copy_to_input_tee, int input_tee, MD5_CTX *context, fflush(stdout); fflush(stderr); del = 0; + if (byte_return) { + break; + } custom_exit(ExitCode::SHORT_READ); } else { + if (byte_return) { + break; + } custom_exit(ExitCode::SHORT_READ); } } @@ -309,7 +321,7 @@ Sirikata::Array1d transfer_and_md5(Sirikata::Array1d he uint8_t buffer[65536] = { 0 }; #ifdef _WIN32 std::thread worker(std::bind(&md5_and_copy_to_tee, - copy_to_input_tee, input_tee, &context, input_size, start_byte, end_byte, close_input, is_socket)); + copy_to_input_tee, input_tee, &context, input_size, start_byte, end_byte, close_input, is_socket, byte_return)); #if 1 while(!failed) { auto old_size = storage->size(); diff --git a/src/io/ioutil.hh b/src/io/ioutil.hh index 3f3d67bb..3d076c64 100644 --- a/src/io/ioutil.hh +++ b/src/io/ioutil.hh @@ -1,5 +1,5 @@ -#ifndef _SIRIKIATA_IO_UTIL_HH_ -#define _SIRIKIATA_IO_UTIL_HH_ +#ifndef SIRIKIATA_IO_UTIL_HH_ +#define SIRIKIATA_IO_UTIL_HH_ #ifndef _WIN32 #include #include diff --git a/src/io/seccomp-bpf.hh b/src/io/seccomp-bpf.hh index 95247db7..be189968 100644 --- a/src/io/seccomp-bpf.hh +++ b/src/io/seccomp-bpf.hh @@ -9,8 +9,8 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef _SECCOMP_BPF_H_ -#define _SECCOMP_BPF_H_ +#ifndef SECCOMP_BPF_H_ +#define SECCOMP_BPF_H_ #define _GNU_SOURCE 1 #include diff --git a/src/lepton/bitops.hh b/src/lepton/bitops.hh index cffa6163..41dd7293 100644 --- a/src/lepton/bitops.hh +++ b/src/lepton/bitops.hh @@ -31,22 +31,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#define RBITS( c, n ) ( c & ( 0xFF >> (8 - n) ) ) -#define LBITS( c, n ) ( c >> (8 - n) ) -#define MBITS( c, l, r ) ( RBITS( c,l ) >> r ) -#define RBITS16( c, n ) ( c & ( 0xFFFFFFFF >> (16 - n) ) ) -#define LBITS16( c, n ) ( c >> (16 - n) ) +#define RBITS( c, n ) ( (c) & ( 0xFF >> (8 - (n)) ) ) +#define LBITS( c, n ) ( (c) >> (8 - (n)) ) +#define MBITS( c, l, r ) ( RBITS( c,l ) >> (r) ) +#define RBITS16( c, n ) ( (c) & ( 0xFFFFFFFF >> (16 - (n)) ) ) +#define LBITS16( c, n ) ( (c) >> (16 - (n)) ) #define MBITS16( c, l, r ) ( RBITS16( c,l ) >> r ) -#define RBITS32( c, n ) ( c & ( 0xFFFFFFFF >> (32 - n) ) ) -#define LBITS32( c, n ) ( c >> (32 - n) ) -#define MBITS32( c, l, r ) ( RBITS32( c,l ) >> r ) +#define RBITS32( c, n ) ( (c) & ( 0xFFFFFFFF >> (32 - (n)) ) ) +#define LBITS32( c, n ) ( (c) >> (32 - (n)) ) +#define MBITS32( c, l, r ) ( RBITS32( c,l ) >> (r) ) -#define RBITS64( c, n ) (n == 0 ? 0ULL : ( (c) & ( 0xFFFFFFFFFFFFFFFFULL >> (64 - (n)) ) )) -#define LBITS64( c, n ) ( c >> (64 - n) ) +#define RBITS64( c, n ) ((n) == 0 ? 0ULL : ( (c) & ( 0xFFFFFFFFFFFFFFFFULL >> (64 - (n)) ) )) +#define LBITS64( c, n ) ( (c) >> (64 - (n)) ) #define MBITS64( c, l, r ) (((r) >= 64) ? 0 : ( RBITS64( c,l ) >> (r) )) -#define BITN( c, n ) ( (c >> n) & 0x1 ) -#define FDIV2( v, p ) ( ( v < 0 ) ? -( (-v) >> p ) : ( v >> p ) ) +#define BITN( c, n ) ( ((c) >> (n)) & 0x1 ) +#define FDIV2( v, p ) ( ( (v) < 0 ) ? -( (-v) >> (p) ) : ( (v) >> (p) ) ) #define BTST_BUFF 1024 * 1024 diff --git a/src/lepton/component_info.hh b/src/lepton/component_info.hh index 2b0a5b31..03780647 100644 --- a/src/lepton/component_info.hh +++ b/src/lepton/component_info.hh @@ -1,6 +1,6 @@ /* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -#ifndef _COMPONENT_INFO_HH_ -#define _COMPONENT_INFO_HH_ +#ifndef COMPONENT_INFO_HH_ +#define COMPONENT_INFO_HH_ struct componentInfo { unsigned short* qtable; // quantization table int huffdc; // no of huffman table (DC) diff --git a/src/lepton/concat.cc b/src/lepton/concat.cc index 27b20772..f7330cc0 100644 --- a/src/lepton/concat.cc +++ b/src/lepton/concat.cc @@ -1,3 +1,4 @@ +#include #include "../vp8/util/memory.hh" #include "../io/BrotliCompression.hh" #include "../io/ioutil.hh" diff --git a/src/lepton/jpgcoder.cc b/src/lepton/jpgcoder.cc index 3e485c45..18ead111 100644 --- a/src/lepton/jpgcoder.cc +++ b/src/lepton/jpgcoder.cc @@ -123,7 +123,9 @@ bool g_skip_validation = false; #define IPOS(w,v,h) ( ( v * w ) + h ) #define NPOS(n1,n2,p) ( ( ( p / n1 ) * n2 ) + ( p % n1 ) ) #define ROUND_F(v1) ( (v1 < 0) ? (int) (v1 - 0.5) : (int) (v1 + 0.5) ) -#define B_SHORT(v1,v2) ( ( ((int) v1) << 8 ) + ((int) v2) ) +inline uint16_t B_SHORT(uint8_t v1, uint8_t v2) { + return ( ( ((int) v1) << 8 ) + ((int) v2) ); +} #define CLAMPED(l,h,v) ( ( v < l ) ? l : ( v > h ) ? h : v ) #define MEM_ERRMSG "out of memory error" @@ -190,13 +192,6 @@ enum ACTION { lepton_concatenate = 5 }; -enum F_TYPE { - JPEG = 0, - UJG = 1, - LEPTON=2, - UNK = 3 -}; - namespace { uint32_t LEtoUint32(const uint8_t*buffer) { @@ -281,7 +276,7 @@ bool is_jpeg_header(Sirikata::Array1d header) { // baseline single threaded decoding need only two rows of the image in memory bool setup_imginfo_jpg(bool only_allocate_two_image_rows); -bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segment ); +bool parse_jfif_jpg( unsigned char type, unsigned int len, uint32_t alloc_len, unsigned char* segment ); bool rebuild_header_jpg( void ); int decode_block_seq( abitreader* huffr, huffTree* dctree, huffTree* actree, short* block ); @@ -310,7 +305,7 @@ int next_mcupos( int* mcu, int* cmp, int* csc, int* sub, int* dpos, int* rstw, i int next_mcuposn( int* cmp, int* dpos, int* rstw ); int skip_eobrun( int* cmp, int* dpos, int* rstw, unsigned int* eobrun ); -bool build_huffcodes( unsigned char *clen, unsigned char *cval, +bool build_huffcodes( unsigned char *clen, uint32_t clenlen, unsigned char *cval, uint32_t cvallen, huffCodes *hc, huffTree *ht ); @@ -528,6 +523,7 @@ int verbosity = 0; // level of verbosity bool overwrite = false; // overwrite files yes / no int err_tresh = 1; // error threshold ( proceed on warnings yes (2) / no (1) ) bool disc_meta = false; // discard meta-info yes / no +bool clobber = false; // clobber files yes / no ( same as "overwrite"? ) bool developer = false; // allow developers functions yes/no ACTION action = comp; // what to do with JPEG/UJG files @@ -1144,6 +1140,9 @@ int initialize_options( int argc, const char*const * argv ) else if ( strcmp((*argv), "-d" ) == 0 ) { disc_meta = true; } + else if ( strcmp((*argv), "-clobber" ) == 0 ) { + clobber = true; + } else if ( strcmp((*argv), "-dev") == 0 ) { developer = true; } else if ( ( strcmp((*argv), "-ujg") == 0 ) || @@ -1481,7 +1480,7 @@ int open_fdout(const char *ifilename, } } do { - retval = open(ofilename.c_str(), O_WRONLY|O_CREAT|O_TRUNC + retval = open(ofilename.c_str(), O_WRONLY|O_CREAT| (clobber ? 0 : O_EXCL) |O_TRUNC #ifdef _WIN32 | O_BINARY #endif @@ -1498,6 +1497,7 @@ int open_fdout(const char *ifilename, while(write(2, errormessage, strlen(errormessage)) == -1 && errno == EINTR) {} while(write(2, ofilename.c_str(), ofilename.length()) == -1 && errno == EINTR) {} while(write(2, "\n", 1) == -1 && errno == EINTR) {} + if (errno == EEXIST) { custom_exit(ExitCode::FILE_ALREADY_EXISTS); } custom_exit(ExitCode::FILE_NOT_FOUND); } return retval; @@ -2842,7 +2842,7 @@ bool decode_jpeg(const std::vector > & huff_input_ } else { hdr_seg_data = &( hdrdata[ hpos ] ); } - if ( !parse_jfif_jpg( type, len, hdr_seg_data ) ) { + if ( !parse_jfif_jpg( type, len, len, hdr_seg_data ) ) { delete huffr; return false; } @@ -3345,10 +3345,11 @@ bool recode_jpeg( void ) // seek till start-of-scan, parse only DHT, DRI and SOS for ( type = 0x00; type != 0xDA; ) { if ( hpos >= hdrs ) break; - type = hdrdata[ hpos + 1 ]; - len = 2 + B_SHORT( hdrdata[ hpos + 2 ], hdrdata[ hpos + 3 ] ); + type = hpos + 1 < hdrs ? hdrdata[ hpos + 1 ] : 0; + len = 2 + B_SHORT( (size_t)hpos + 2 < (size_t)hdrs ? hdrdata[ (size_t)hpos + 2 ]:0, + (size_t)hpos + 3 < (size_t)hdrs ? hdrdata[ (size_t)hpos + 3 ] :0); if ( ( type == 0xC4 ) || ( type == 0xDA ) || ( type == 0xDD ) ) { - if ( !parse_jfif_jpg( type, len, &( hdrdata[ hpos ] ) ) ) { + if ( !parse_jfif_jpg( type, len, len > hdrs - hpos ? hdrs - hpos : len, &( hdrdata[ hpos ] ) ) ) { delete huffw; delete storw; return false; @@ -3705,6 +3706,12 @@ bool recode_jpeg( void ) delete storw; } // store last scan & restart positions + if ((size_t)scnc >= scnp.size()) { + delete huffw; + fprintf( stderr, MEM_ERRMSG ); + errorlevel.store(2); + return false; + } scnp.at(scnc) = hufs; if ( !rstp.empty() ) rstp.at(rstc) = hufs; @@ -3830,6 +3837,7 @@ bool write_ujpg(std::vector row_thread_handoffs, jpeg_file_raw_bytes->size() - start_byte)); } else { prefix_grbgdata = aligned_alloc(1); // so it's nonnull + prefix_grbgdata[0] = 0; } } Sirikata::MemReadWriter mrw((Sirikata::JpegAllocator())); @@ -4163,7 +4171,7 @@ bool read_ujpg( void ) Sirikata::BrotliCodec::Decompress(compressed_header_buffer.data(), compressed_header_buffer.size(), JpegAllocator(), - max_file_size * 2 + 128 * 1024 * 1024)); + ((size_t)max_file_size) * 2 + 128 * 1024 * 1024)); if (uncompressed_header_buffer.second) { always_assert(false && "Data not properly zlib coded"); return false; @@ -4188,6 +4196,7 @@ bool read_ujpg( void ) ReadFull(header_reader, ujpg_mrk, 4 ); hdrs = LEtoUint32(ujpg_mrk); hdrdata = (unsigned char*) aligned_alloc(hdrs); + memset(hdrdata, 0, hdrs); if ( hdrdata == NULL ) { fprintf( stderr, MEM_ERRMSG ); errorlevel.store(2); @@ -4270,6 +4279,7 @@ bool read_ujpg( void ) ReadFull(header_reader, ujpg_mrk, 4); grbs = LEtoUint32(ujpg_mrk); grbgdata = aligned_alloc(grbs); + memset(grbgdata, 0, sizeof(grbs)); if ( grbgdata == NULL ) { fprintf( stderr, MEM_ERRMSG ); errorlevel.store(2); @@ -4287,6 +4297,7 @@ bool read_ujpg( void ) ReadFull(header_reader, ujpg_mrk, 4); prefix_grbs = LEtoUint32(ujpg_mrk); prefix_grbgdata = aligned_alloc(prefix_grbs); + memset(prefix_grbgdata, 0, sizeof(prefix_grbs)); if ( prefix_grbgdata == NULL ) { fprintf( stderr, MEM_ERRMSG ); errorlevel.store(2); @@ -4445,11 +4456,11 @@ bool setup_imginfo_jpg(bool only_allocate_two_image_rows) // header parser loop while ( hpos < hdrs ) { - type = hdrdata[ hpos + 1 ]; - len = 2 + B_SHORT( hdrdata[ hpos + 2 ], hdrdata[ hpos + 3 ] ); + type = hpos + 1 < hdrs ? hdrdata[ hpos + 1 ] : 0; + len = 2 + B_SHORT( hpos + 2 < hdrs ? hdrdata[ hpos + 2 ] : 0, hpos + 3 < hdrs ? hdrdata[ hpos + 3 ] : 0); // do not parse DHT & DRI if ( ( type != 0xDA ) && ( type != 0xC4 ) && ( type != 0xDD ) ) { - if ( !parse_jfif_jpg( type, len, &( hdrdata[ hpos ] ) ) ) + if ( !parse_jfif_jpg( type, len, hdrs-hpos, &( hdrdata[ hpos ] ) ) ) return false; } hpos += len; @@ -4530,7 +4541,7 @@ bool setup_imginfo_jpg(bool only_allocate_two_image_rows) /* ----------------------------------------------- Parse routines for JFIF segments ----------------------------------------------- */ -bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segment ) +bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned int alloc_len, unsigned char* segment ) { unsigned int hpos = 4; // current position in segment, start after segment header int lval, rval; // temporary variables @@ -4544,14 +4555,15 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen case 0xC4: // DHT segment // build huffman trees & codes while ( hpos < len ) { - lval = LBITS( segment[ hpos ], 4 ); - rval = RBITS( segment[ hpos ], 4 ); + lval = LBITS( hpos < alloc_len ? segment[ hpos ] : 0, 4 ); + rval = RBITS( hpos < alloc_len ? segment[ hpos ]: 0, 4 ); if ( ((lval < 0) || (lval >= 2)) || ((rval < 0) || (rval >= 4)) ) break; hpos++; // build huffman codes & trees - if (!build_huffcodes( &(segment[ hpos + 0 ]), &(segment[ hpos + 16 ]), + if (!build_huffcodes( &(segment[ hpos + 0 ]), alloc_len > hpos ? alloc_len - hpos : 0, + &(segment[ hpos + 16 ]), alloc_len > hpos + 16 ? alloc_len - hpos - 16 : 0, &(hcodes[ lval ][ rval ]), &(htrees[ lval ][ rval ]) )) { errorlevel.store(2); return false; @@ -4560,7 +4572,7 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen skip = 16; for ( i = 0; i < 16; i++ ) - skip += ( int ) segment[ hpos + i ]; + skip += ( int ) (hpos + i < alloc_len ? segment[ hpos + i ] : 0); hpos += skip; } @@ -4575,14 +4587,14 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen case 0xDB: // DQT segment // copy quantization tables to internal memory while ( hpos < len ) { - lval = LBITS( segment[ hpos ], 4 ); - rval = RBITS( segment[ hpos ], 4 ); + lval = LBITS( hpos < alloc_len ? segment[ hpos ] : 0, 4 ); + rval = RBITS( hpos < alloc_len ? segment[ hpos ] : 0, 4 ); if ( (lval < 0) || (lval >= 2) ) break; if ( (rval < 0) || (rval >= 4) ) break; hpos++; if ( lval == 0 ) { // 8 bit precision for ( i = 0; i < 64; i++ ) { - qtables[ rval ][ i ] = ( unsigned short ) segment[ hpos + i ]; + qtables[ rval ][ i ] = ( unsigned short ) (hpos + i < alloc_len ? segment[ hpos + i ] : 0); if ( qtables[ rval ][ i ] == 0 ) break; } hpos += 64; @@ -4590,7 +4602,7 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen else { // 16 bit precision for ( i = 0; i < 64; i++ ) { qtables[ rval ][ i ] = - B_SHORT( segment[ hpos + (2*i) ], segment[ hpos + (2*i) + 1 ] ); + B_SHORT( (hpos + (2*i)< alloc_len ? segment[ hpos + (2*i) ] : 0), (hpos + 2*i+1 < alloc_len?segment[ hpos + (2*i) + 1 ]:0) ); if ( qtables[ rval ][ i ] == 0 ) break; } hpos += 128; @@ -4607,12 +4619,12 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen case 0xDD: // DRI segment // define restart interval - rsti = B_SHORT( segment[ hpos ], segment[ hpos + 1 ] ); + rsti = B_SHORT( hpos < alloc_len ? segment[ hpos ]:0, hpos +1 < alloc_len ?segment[ hpos + 1 ]:0 ); return true; case 0xDA: // SOS segment // prepare next scan - cs_cmpc = segment[ hpos ]; + cs_cmpc = hpos < alloc_len ? segment[ hpos ] : 0; if ( cs_cmpc > cmpc ) { fprintf( stderr, "%i components in scan, only %i are allowed", cs_cmpc, cmpc ); @@ -4621,15 +4633,15 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen } hpos++; for ( i = 0; i < cs_cmpc; i++ ) { - for ( cmp = 0; ( segment[ hpos ] != cmpnfo[ cmp ].jid ) && ( cmp < cmpc ); cmp++ ); + for ( cmp = 0; ( (hpos < alloc_len ? segment[ hpos ]:0) != cmpnfo[ cmp ].jid ) && ( cmp < cmpc ); cmp++ ); if ( cmp == cmpc ) { fprintf( stderr, "component id mismatch in start-of-scan" ); errorlevel.store(2); return false; } cs_cmp[ i ] = cmp; - cmpnfo[ cmp ].huffdc = LBITS( segment[ hpos + 1 ], 4 ); - cmpnfo[ cmp ].huffac = RBITS( segment[ hpos + 1 ], 4 ); + cmpnfo[ cmp ].huffdc = LBITS( hpos + 1< alloc_len ? segment[ hpos + 1 ]:0, 4 ); + cmpnfo[ cmp ].huffac = RBITS( hpos + 1 < alloc_len ? segment[ hpos + 1 ]:0, 4 ); if ( ( cmpnfo[ cmp ].huffdc < 0 ) || ( cmpnfo[ cmp ].huffdc >= 4 ) || ( cmpnfo[ cmp ].huffac < 0 ) || ( cmpnfo[ cmp ].huffac >= 4 ) ) { fprintf( stderr, "huffman table number mismatch" ); @@ -4638,10 +4650,10 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen } hpos += 2; } - cs_from = segment[ hpos + 0 ]; - cs_to = segment[ hpos + 1 ]; - cs_sah = LBITS( segment[ hpos + 2 ], 4 ); - cs_sal = RBITS( segment[ hpos + 2 ], 4 ); + cs_from = hpos < alloc_len ? segment[ hpos + 0 ]:0; + cs_to = hpos + 1 < alloc_len ? segment[ hpos + 1 ]:0; + cs_sah = LBITS( hpos + 2 < alloc_len ? segment[ hpos + 2 ]:0, 4 ); + cs_sal = RBITS( hpos +2 < alloc_len ? segment[ hpos + 2 ]:0, 4 ); // check for errors if ( ( cs_from > cs_to ) || ( cs_from > 63 ) || ( cs_to > 63 ) ) { fprintf( stderr, "spectral selection parameter out of range" ); @@ -4671,7 +4683,7 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen jpegtype = 1; // check data precision, only 8 bit is allowed - lval = segment[ hpos ]; + lval = hpos < alloc_len ? segment[ hpos ]:0; if ( lval != 8 ) { fprintf( stderr, "%i bit data precision is not supported", lval ); errorlevel.store(2); @@ -4679,9 +4691,9 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen } // image size, height & component count - imgheight = B_SHORT( segment[ hpos + 1 ], segment[ hpos + 2 ] ); - imgwidth = B_SHORT( segment[ hpos + 3 ], segment[ hpos + 4 ] ); - cmpc = segment[ hpos + 5 ]; + imgheight = B_SHORT( hpos + 1 < alloc_len ? segment[ hpos + 1 ]:0, hpos + 2 < alloc_len ?segment[ hpos + 2 ] :0); + imgwidth = B_SHORT( hpos + 3 < alloc_len ?segment[ hpos + 3 ]:0, hpos + 4 < alloc_len ?segment[ hpos + 4 ]:0 ); + cmpc = hpos + 5 < alloc_len ? segment[ hpos + 5 ]:0; if ( cmpc > 4 ) { cmpc = 4; fprintf( stderr, "image has %i components, max 4 are supported", cmpc ); @@ -4691,9 +4703,9 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen hpos += 6; // components contained in image for ( cmp = 0; cmp < cmpc; cmp++ ) { - cmpnfo[ cmp ].jid = segment[ hpos ]; - cmpnfo[ cmp ].sfv = LBITS( segment[ hpos + 1 ], 4 ); - cmpnfo[ cmp ].sfh = RBITS( segment[ hpos + 1 ], 4 ); + cmpnfo[ cmp ].jid = hpos < alloc_len ? segment[ hpos ]:0; + cmpnfo[ cmp ].sfv = LBITS( hpos + 1 < alloc_len ? segment[ hpos + 1 ]:0, 4 ); + cmpnfo[ cmp ].sfh = RBITS( hpos + 1 < alloc_len ? segment[ hpos + 1 ]:0, 4 ); if (cmpnfo[ cmp ].sfv > 4 || cmpnfo[ cmp ].sfh > 4) { custom_exit(ExitCode::SAMPLING_BEYOND_FOUR_UNSUPPORTED); @@ -4704,7 +4716,7 @@ bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segmen custom_exit(ExitCode::SAMPLING_BEYOND_TWO_UNSUPPORTED); } #endif - uint32_t quantization_table_value = segment[ hpos + 2 ]; + uint32_t quantization_table_value = hpos + 2 < alloc_len ? segment[ hpos + 2 ]:0; if (quantization_table_value >= qtables.size()) { errorlevel.store(2); return false; @@ -4837,22 +4849,29 @@ bool rebuild_header_jpg( void ) abytewriter* hdrw; // new header writer unsigned char type = 0x00; // type of current marker segment - unsigned int len = 0; // length of current marker segment - unsigned int hpos = 0; // position in header + uint32_t len = 0; // length of current marker segment + uint32_t hpos = 0; // position in header // start headerwriter hdrw = new abytewriter( 4096 ); // header parser loop - while ( hpos < hdrs ) { - type = hdrdata[ hpos + 1 ]; - len = 2 + B_SHORT( hdrdata[ hpos + 2 ], hdrdata[ hpos + 3 ] ); + while ( hpos < hdrs && (uint64_t)hpos + 3 < (uint64_t)hdrs ) { + type = hpos + 1 < hdrs ? hdrdata[ hpos + 1 ] : 0; + len = 2 + B_SHORT( hpos + 2 < hdrs ? hdrdata[ hpos + 2 ]:0, hpos + 3 < hdrs ? hdrdata[ hpos + 3 ] :0); // discard any unneeded meta info if ( ( type == 0xDA ) || ( type == 0xC4 ) || ( type == 0xDB ) || ( type == 0xC0 ) || ( type == 0xC1 ) || ( type == 0xC2 ) || ( type == 0xDD ) ) { - hdrw->write_n( &(hdrdata[ hpos ]), len ); + uint32_t to_copy = hpos + len < hdrs ? len : hdrs - hpos; + hdrw->write_n( &(hdrdata[ hpos ]), to_copy); + if (to_copy < len) { + for (uint32_t i = 0;i write_n(&zero, 1); + } + } } hpos += len; } @@ -5484,7 +5503,7 @@ int skip_eobrun( int* cmp, int* dpos, int* rstw, unsigned int* eobrun ) /* ----------------------------------------------- creates huffman-codes & -trees from dht-data ----------------------------------------------- */ -bool build_huffcodes( unsigned char *clen, unsigned char *cval, huffCodes *hc, huffTree *ht ) +bool build_huffcodes( unsigned char *clen, uint32_t clenlen, unsigned char *cval, uint32_t cvallen, huffCodes *hc, huffTree *ht ) { int nextfree; int code; @@ -5506,9 +5525,12 @@ bool build_huffcodes( unsigned char *clen, unsigned char *cval, huffCodes *hc // symbol-value of code is its position in the table for( i = 0; i < 16; i++ ) { - for( j = 0; j < (int) clen[i & 0xff]; j++ ) { - hc->clen[ (int) cval[k&0xff]&0xff] = 1 + i; - hc->cval[ (int) cval[k&0xff]&0xff] = code; + uint32_t clen_index = i & 0xff; + for( j = 0; j < (int) (clen_index < clenlen ? clen[clen_index] : 0); j++ ) { + uint32_t cval_index = k&0xff; + uint8_t cval_val= cval_index < cvallen ? cval[cval_index] : 0; + hc->clen[ (int) cval_val&0xff] = 1 + i; + hc->cval[ (int) cval_val&0xff] = code; k++; code++; @@ -5620,8 +5642,8 @@ bool write_info( void ) fprintf( fp, " type length hpos\n" ); // header parser loop for ( hpos = 0; hpos < hdrs; hpos += len ) { - type = hdrdata[ hpos + 1 ]; - len = 2 + B_SHORT( hdrdata[ hpos + 2 ], hdrdata[ hpos + 3 ] ); + type = hpos + 1 < hdrs ? hdrdata[ hpos + 1 ] : 0 ; + len = 2 + B_SHORT( hpos + 2 < hdrs ? hdrdata[ hpos + 2 ] : 0, hpos + 3 < hdrs ? hdrdata[ hpos + 3 ] : 0); fprintf( fp, " FF%2X %6i %6i\n", type, len, hpos ); } fprintf( fp, " _END 0 %6i\n", hpos ); diff --git a/src/lepton/jpgcoder.hh b/src/lepton/jpgcoder.hh index ded2ee2b..189a4463 100644 --- a/src/lepton/jpgcoder.hh +++ b/src/lepton/jpgcoder.hh @@ -1,6 +1,6 @@ /* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -#ifndef _JPGCODER_HH_ -#define _JPGCODER_HH_ +#ifndef JPGCODER_HH_ +#define JPGCODER_HH_ #include #include #include "../vp8/util/nd_array.hh" diff --git a/src/lepton/lepton_codec.hh b/src/lepton/lepton_codec.hh index 1cf74da4..d7fcb13b 100644 --- a/src/lepton/lepton_codec.hh +++ b/src/lepton/lepton_codec.hh @@ -1,5 +1,5 @@ -#ifndef _LEPTON_CODEC_HH_ -#define _LEPTON_CODEC_HH_ +#ifndef LEPTON_CODEC_HH_ +#define LEPTON_CODEC_HH_ #include "jpgcoder.hh" #include "model.hh" #include "bool_decoder.hh" diff --git a/src/lepton/recoder.cc b/src/lepton/recoder.cc index e7fd8e9a..27726fd0 100644 --- a/src/lepton/recoder.cc +++ b/src/lepton/recoder.cc @@ -2,7 +2,9 @@ #include #include #include - +#ifdef _WIN32 +#include +#endif #include "uncompressed_components.hh" #include "recoder.hh" #include "bitops.hh" @@ -25,7 +27,7 @@ extern Sirikata::Array1d cmpnfo; extern bool embedded_jpeg; extern int grbs; // size of garbage -extern int hdrs; // size of header +extern uint32_t hdrs; // size of header extern Sirikata::Array1d, 4> qtables; // quantization tables extern Sirikata::Array1d, 2> hcodes; // huffman codes extern Sirikata::Array1d, 2> htrees; // huffman decoding trees @@ -47,7 +49,7 @@ static void nop(){} void check_decompression_memory_bound_ok(); -bool parse_jfif_jpg( unsigned char type, unsigned int len, unsigned char* segment ); +bool parse_jfif_jpg( unsigned char type, unsigned int len, uint32_t alloc_len, unsigned char* segment ); #define B_SHORT(v1,v2) ( ( ((int) v1) << 8 ) + ((int) v2) ) int find_aligned_end_64_scalar(const int16_t *block) { @@ -415,7 +417,7 @@ unsigned int handle_initial_segments( bounded_iostream * const str_out ) while ( true ) { /* step 1: have we exhausted the headers without reaching the scan? */ - if ( static_cast( byte_position + 3 ) >= hdrs ) { + if ( static_cast( byte_position + 3 ) >= hdrs ) { std::cerr << "overran headers\n"; return -1; } @@ -434,7 +436,7 @@ unsigned int handle_initial_segments( bounded_iostream * const str_out ) /* step 4: if it's a DHT (0xC4), DRI (0xDD), or SOS (0xDA), parse to mutable globals */ if ( type == 0xC4 || type == 0xDD || type == 0xDA ) { /* XXX make sure parse_jfif_jpg can't overrun hdrdata */ - if ( !parse_jfif_jpg( type, len, hdrdata + byte_position ) ) { return -1; } + if ( !parse_jfif_jpg( type, len, hdrs - byte_position > len ? len : hdrs - byte_position, hdrdata + byte_position ) ) { return -1; } } /* step 5: we parsed the header -- accumulate byte position */ @@ -629,9 +631,13 @@ void recode_physical_thread(BoundedWriter *stream_out, if (thread_handoffs[logical_thread_id+1].luma_y_start != thread_handoffs[logical_thread_id+1].luma_y_end || ujgversion ==1 ) { // make sure we computed the same item that was stored - always_assert(outth.num_overhang_bits == thread_handoffs[logical_thread_id + 1].num_overhang_bits); - always_assert(outth.overhang_byte == thread_handoffs[logical_thread_id + 1].overhang_byte); - always_assert(memcmp(outth.last_dc.begin(), thread_handoffs[logical_thread_id + 1].last_dc.begin(), sizeof(outth.last_dc)) == 0); + if (g_threaded) { + always_assert(outth.num_overhang_bits == thread_handoffs[logical_thread_id + 1].num_overhang_bits); + always_assert(outth.overhang_byte == thread_handoffs[logical_thread_id + 1].overhang_byte); + } + if (g_threaded || thread_handoffs[logical_thread_id + 1].segment_size > 1) { + always_assert(memcmp(outth.last_dc.begin(), thread_handoffs[logical_thread_id + 1].last_dc.begin(), sizeof(outth.last_dc)) == 0); + } } if (physical_thread_id > 0 && stream_out->bytes_written()) { // if 0 are written the bound is not tight always_assert(stream_out->get_bound() == stream_out->bytes_written()); diff --git a/src/lepton/validation.cc b/src/lepton/validation.cc index d951a718..c37cd3b0 100644 --- a/src/lepton/validation.cc +++ b/src/lepton/validation.cc @@ -46,8 +46,9 @@ ValidationContinuation validateAndCompress(int *reader, && strstr(argv[i], "-verif") != argv[i] && strstr(argv[i], "-socket") != argv[i] && strstr(argv[i], "-fork") != argv[i] - && strstr(argv[i], "-listen") != argv[i] - && strstr(argv[i], "-roundtrip") != argv[i]) { + && strstr(argv[i], "-listen") != argv[i] + && strstr(argv[i], "-permissive") != argv[i] + && strstr(argv[i], "-roundtrip") != argv[i]) { args.push_back(argv[i]); } } diff --git a/src/lepton/vp8_decoder.cc b/src/lepton/vp8_decoder.cc index bca25d6d..692e3b17 100644 --- a/src/lepton/vp8_decoder.cc +++ b/src/lepton/vp8_decoder.cc @@ -346,7 +346,9 @@ std::vector VP8ComponentDecoder::initialize_decoder_ th.num_overhang_bits = ThreadHandoff::LEGACY_OVERHANG_BITS; // to make sure we don't use this value th.luma_y_end = colldata->block_height(0); thread_handoff_.insert(thread_handoff_.end(), mark, th); - + if (mark == 0) { // must be at least 1 to do splits; + custom_exit(ExitCode::THREADING_PARTIAL_MCU); + } std::vector luma_splits_tmp(mark - 1); IOUtil::ReadFull(str_in, luma_splits_tmp.data(), sizeof(uint16_t) * (mark - 1)); int sfv_lcm = colldata->min_vertical_luma_multiple(); diff --git a/src/lepton/vp8_encoder.hh b/src/lepton/vp8_encoder.hh index ed012319..77a25b79 100644 --- a/src/lepton/vp8_encoder.hh +++ b/src/lepton/vp8_encoder.hh @@ -1,6 +1,6 @@ /* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -#ifndef _VP8_COMPONENT_ENCODER_HH_ -#define _VP8_COMPONENT_ENCODER_HH_ +#ifndef VP8_COMPONENT_ENCODER_HH_ +#define VP8_COMPONENT_ENCODER_HH_ #include "base_coders.hh" #include "lepton_codec.hh" #include "model.hh" diff --git a/src/vp8/decoder/ans_bool_reader.hh b/src/vp8/decoder/ans_bool_reader.hh index fc09d41d..8f4383c5 100644 --- a/src/vp8/decoder/ans_bool_reader.hh +++ b/src/vp8/decoder/ans_bool_reader.hh @@ -79,7 +79,7 @@ public: r0 = r1; uint32_t cumulative_freq = Rans64DecGet(&local_state, 8); uint32_t prob = branch.prob(); - bool retval = cumulative_freq >= prob; + uint32_t retval = (uint32_t)(cumulative_freq >= prob); uint32_t start = prob & (-(int32_t)retval); uint32_t freq = (prob ^ -retval) + (retval | (retval << 8)); //uint32_t freq = retval ? 256 - prob: prob; diff --git a/src/vp8/decoder/coefs.hh b/src/vp8/decoder/coefs.hh index 38f5b97f..156d5fcb 100644 --- a/src/vp8/decoder/coefs.hh +++ b/src/vp8/decoder/coefs.hh @@ -1,5 +1,5 @@ -#ifndef _COEFS_HH -#define _COEFS_HH +#ifndef COEFS_HH +#define COEFS_HH #include "bool_decoder.hh" #include "model.hh" diff --git a/src/vp8/model/JpegArithmeticCoder.hh b/src/vp8/model/JpegArithmeticCoder.hh index 75d70257..47eeedac 100644 --- a/src/vp8/model/JpegArithmeticCoder.hh +++ b/src/vp8/model/JpegArithmeticCoder.hh @@ -45,8 +45,8 @@ * * Suspension is not currently supported in this module. */ -#ifndef _JPEG_ARITHMETIC_CODER_HH_ -#define _JPEG_ARITHMETIC_CODER_HH_ +#ifndef JPEG_ARITHMETIC_CODER_HH_ +#define JPEG_ARITHMETIC_CODER_HH_ #include "../../io/Reader.hh" diff --git a/src/vp8/model/branch.hh b/src/vp8/model/branch.hh index dd48629f..660c3b83 100644 --- a/src/vp8/model/branch.hh +++ b/src/vp8/model/branch.hh @@ -1,5 +1,5 @@ -#ifndef _BRANCH_HH_ -#define _BRANCH_HH_ +#ifndef BRANCH_HH_ +#define BRANCH_HH_ #include "numeric.hh" #include typedef uint8_t Probability; diff --git a/src/vp8/model/color_context.hh b/src/vp8/model/color_context.hh index e2493f25..b0dc55b9 100644 --- a/src/vp8/model/color_context.hh +++ b/src/vp8/model/color_context.hh @@ -1,5 +1,5 @@ -#ifndef _COLOR_CONTEXT_HH_ -#define _COLOR_CONTEXT_HH_ +#ifndef COLOR_CONTEXT_HH_ +#define COLOR_CONTEXT_HH_ enum class BlockType { Y, Cb, Cr #ifdef ALLOW_FOUR_COLORS diff --git a/src/vp8/model/jpeg_meta.hh b/src/vp8/model/jpeg_meta.hh index 137a0faa..4d739e77 100644 --- a/src/vp8/model/jpeg_meta.hh +++ b/src/vp8/model/jpeg_meta.hh @@ -1,5 +1,5 @@ -#ifndef _JPEG_META_HH -#define _JPEG_META_HH +#ifndef JPEG_META_HH +#define JPEG_META_HH #include #include diff --git a/src/vp8/model/model.hh b/src/vp8/model/model.hh index 5498e621..c65ebad4 100644 --- a/src/vp8/model/model.hh +++ b/src/vp8/model/model.hh @@ -18,6 +18,14 @@ #include "../util/mm_mullo_epi32.hh" #endif +enum F_TYPE { + JPEG = 0, + UJG = 1, + LEPTON=2, + UNK = 3 +}; + +extern F_TYPE filetype; constexpr bool advanced_dc_prediction = true; enum TableParams : unsigned int { @@ -242,6 +250,12 @@ public: icos_idct_edge_8192_dequantized_x((int)color)[pixel_row * 8 + i] = icos_base_8192_scaled[i * 8] * quantization_table_[(int)color][i * 8 + pixel_row]; icos_idct_edge_8192_dequantized_y((int)color)[pixel_row * 8 + i] = icos_base_8192_scaled[i * 8] * quantization_table_[(int)color][pixel_row * 8 + i]; } + if (filetype != LEPTON && icos_idct_edge_8192_dequantized_x((int)color)[pixel_row * 8] == 0) { + custom_exit(ExitCode::UNSUPPORTED_JPEG_WITH_ZERO_IDCT_0); + } + if (filetype != LEPTON && icos_idct_edge_8192_dequantized_y((int)color)[pixel_row * 8] == 0) { + custom_exit(ExitCode::UNSUPPORTED_JPEG_WITH_ZERO_IDCT_0); + } } static const unsigned short int freqmax[] = { diff --git a/src/vp8/model/numeric.hh b/src/vp8/model/numeric.hh index 59671d1d..05b8dff8 100644 --- a/src/vp8/model/numeric.hh +++ b/src/vp8/model/numeric.hh @@ -1,5 +1,5 @@ -#ifndef _VP8_MODEL_NUMERIC_HH_ -#define _VP8_MODEL_NUMERIC_HH_ +#ifndef VP8_MODEL_NUMERIC_HH_ +#define VP8_MODEL_NUMERIC_HH_ //#define DEBUGDECODE //for uint16_t #include diff --git a/src/vp8/util/aligned_block.hh b/src/vp8/util/aligned_block.hh index d24929f9..1ac6c002 100644 --- a/src/vp8/util/aligned_block.hh +++ b/src/vp8/util/aligned_block.hh @@ -1,5 +1,5 @@ -#ifndef _ALIGNED_BLOCK_HH_ -#define _ALIGNED_BLOCK_HH_ +#ifndef ALIGNED_BLOCK_HH_ +#define ALIGNED_BLOCK_HH_ #include #include "nd_array.hh" #include "jpeg_meta.hh" diff --git a/src/vp8/util/billing.hh b/src/vp8/util/billing.hh index b32ed825..58c42bf7 100644 --- a/src/vp8/util/billing.hh +++ b/src/vp8/util/billing.hh @@ -1,8 +1,8 @@ #include #include "memory.hh" #include "nd_array.hh" -#ifndef _BILLING_HH_ -#define _BILLING_HH_ +#ifndef BILLING_HH_ +#define BILLING_HH_ #define FOREACH_BILLING_TYPE(CB) \ CB(HEADER) \ CB(DELIMITERS) \ diff --git a/src/vp8/util/block_based_image.hh b/src/vp8/util/block_based_image.hh index 84fd7971..25c7bfdd 100644 --- a/src/vp8/util/block_based_image.hh +++ b/src/vp8/util/block_based_image.hh @@ -1,5 +1,5 @@ -#ifndef _BLOCK_BASED_IMAGE_HH_ -#define _BLOCK_BASED_IMAGE_HH_ +#ifndef BLOCK_BASED_IMAGE_HH_ +#define BLOCK_BASED_IMAGE_HH_ #include "memory.hh" #include "aligned_block.hh" #include "block_context.hh" diff --git a/src/vp8/util/block_context.hh b/src/vp8/util/block_context.hh index 9a58d277..606abc82 100644 --- a/src/vp8/util/block_context.hh +++ b/src/vp8/util/block_context.hh @@ -1,5 +1,5 @@ -#ifndef _BLOCK_CONTEXT_HH_ -#define _BLOCK_CONTEXT_HH_ +#ifndef BLOCK_CONTEXT_HH_ +#define BLOCK_CONTEXT_HH_ #include "options.hh" #ifndef USE_SCALAR diff --git a/src/vp8/util/debug.hh b/src/vp8/util/debug.hh index a66745f7..e0034ffb 100644 --- a/src/vp8/util/debug.hh +++ b/src/vp8/util/debug.hh @@ -1,5 +1,5 @@ -#ifndef _DEBUG_HH_ -#define _DEBUG_HH_ +#ifndef DEBUG_HH_ +#define DEBUG_HH_ extern bool g_threaded; namespace LeptonDebug { extern int raw_decoded_fp_Y; diff --git a/src/vp8/util/memory.hh b/src/vp8/util/memory.hh index 91dad30e..19a8e018 100644 --- a/src/vp8/util/memory.hh +++ b/src/vp8/util/memory.hh @@ -1,5 +1,5 @@ -#ifndef _MEMORY_HH_ -#define _MEMORY_HH_ +#ifndef MEMORY_HH_ +#define MEMORY_HH_ #if defined(__cplusplus) || defined(c_plusplus) #include #include @@ -26,6 +26,7 @@ extern bool g_use_seccomp; CB(THREADING_PARTIAL_MCU,12) \ CB(VERSION_UNSUPPORTED,13) \ CB(ONLY_GARBAGE_NO_JPEG,14) \ + CB(FILE_ALREADY_EXISTS,17) \ CB(OS_ERROR,33) \ CB(HEADER_TOO_LARGE,34) \ CB(DIMENSIONS_TOO_LARGE,35) \ @@ -35,6 +36,7 @@ extern bool g_use_seccomp; CB(EARLY_EXIT,40) \ CB(ROUNDTRIP_FAILURE, 41) \ CB(UNSUPPORTED_JPEG, 42) \ + CB(UNSUPPORTED_JPEG_WITH_ZERO_IDCT_0, 43) \ CB(COULD_NOT_BIND_PORT, 127) \ #define MAKE_EXIT_CODE_ENUM(ITEM, VALUE) ITEM=VALUE, diff --git a/src/vp8/util/nd_array.hh b/src/vp8/util/nd_array.hh index 353f7e57..ddda644e 100644 --- a/src/vp8/util/nd_array.hh +++ b/src/vp8/util/nd_array.hh @@ -30,8 +30,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SIRIKATA_ARRAY_ND_HPP_ -#define _SIRIKATA_ARRAY_ND_HPP_ +#ifndef SIRIKATA_ARRAY_ND_HPP_ +#define SIRIKATA_ARRAY_ND_HPP_ #include #include #include diff --git a/src/vp8/util/options.hh b/src/vp8/util/options.hh index cc1ffb6b..dcf57def 100644 --- a/src/vp8/util/options.hh +++ b/src/vp8/util/options.hh @@ -1,5 +1,5 @@ -#ifndef _OPTIONS_HH_ -#define _OPTIONS_HH_ +#ifndef OPTIONS_HH_ +#define OPTIONS_HH_ enum { VECTORIZE = 1, diff --git a/test_suite/test_clobber.sh b/test_suite/test_clobber.sh new file mode 100755 index 00000000..d5ca7f82 --- /dev/null +++ b/test_suite/test_clobber.sh @@ -0,0 +1,26 @@ +#!/bin/sh +export A=`mktemp` +export B=`mktemp`.lep + +head -c 4K /dev/urandom > $B + +echo "attempting default no-clobber..." +./lepton "$A" "$B" +if [ $? -ne 17 ]; then + echo "did not receive clobber exit status of 17" + echo "FAILING TEST" + exit 1 +fi + +echo "attempting clobber..." +./lepton -clobber "$A" "$B" +BLEP_SZ=$(stat --printf="%s" "$B") +if [ $BLEP_SZ -ne 0 ]; then + echo "should've blepped to 0 by truncating $B. Instead, got $BLEP_SZ." + echo "FAILING TEST" + exit 1 +fi + +rm $A +rm $B +echo SUCCESS diff --git a/test_suite/test_permissive.sh b/test_suite/test_permissive.sh index 89fb9265..f1fff456 100755 --- a/test_suite/test_permissive.sh +++ b/test_suite/test_permissive.sh @@ -26,8 +26,8 @@ ls -l "$E".lep || exit 1 ls -l "$F".lep || exit 1 export tmp=`mktemp` export tmp2=`mktemp` -./lepton "$C".lep "$tmp" -./lepton "$D".lep "$tmp2" +./lepton -clobber "$C".lep "$tmp" +./lepton -clobber "$D".lep "$tmp2" diff "$C" "$tmp" || exit 1 diff "$D" "$tmp2" || exit 1 for i in "$A" "$D" "$E"; do