[x265-commits] [x265] y4m: better handling of eof during frame header reads

Steve Borho steve at borho.org
Tue Feb 4 06:33:57 CET 2014


details:   http://hg.videolan.org/x265/rev/4b8901ae94ec
branches:  stable
changeset: 5997:4b8901ae94ec
user:      Steve Borho <steve at borho.org>
date:      Mon Feb 03 23:32:00 2014 -0600
description:
y4m: better handling of eof during frame header reads

It wasn't checking the stream state properly (a bug introduced when ifs was made
into a pointer for stdin) and doing a memcmp against possibly uninitialized
stack memory, which just happened to usually have a proper frame header in it
since the reader thread stack use is very predictable.

This was the last warning reported by valgrind on the stable branch
Subject: [x265] Merge with stable

details:   http://hg.videolan.org/x265/rev/f121e16811be
branches:  
changeset: 5998:f121e16811be
user:      Steve Borho <steve at borho.org>
date:      Mon Feb 03 23:33:36 2014 -0600
description:
Merge with stable

diffstat:

 source/CMakeLists.txt                               |    73 +-
 source/Lib/TLibCommon/CommonDef.h                   |     2 +-
 source/Lib/TLibCommon/ContextTables.h               |    59 +-
 source/Lib/TLibCommon/TComBitStream.cpp             |     4 +-
 source/Lib/TLibCommon/TComDataCU.cpp                |   167 +-
 source/Lib/TLibCommon/TComDataCU.h                  |    18 +-
 source/Lib/TLibCommon/TComMotionInfo.h              |     3 -
 source/Lib/TLibCommon/TComPattern.cpp               |    98 -
 source/Lib/TLibCommon/TComPattern.h                 |    52 -
 source/Lib/TLibCommon/TComPic.h                     |     3 +
 source/Lib/TLibCommon/TComPicYuv.cpp                |     6 +-
 source/Lib/TLibCommon/TComPicYuvMD5.cpp             |     3 +
 source/Lib/TLibCommon/TComPrediction.cpp            |    62 +-
 source/Lib/TLibCommon/TComPrediction.h              |     3 -
 source/Lib/TLibCommon/TComRom.cpp                   |     9 +-
 source/Lib/TLibCommon/TComRom.h                     |     7 -
 source/Lib/TLibCommon/TComTrQuant.cpp               |     7 +-
 source/Lib/TLibCommon/TComTrQuant.h                 |     8 +-
 source/Lib/TLibCommon/TComYuv.cpp                   |    55 +-
 source/Lib/TLibCommon/TypeDef.h                     |    11 +-
 source/Lib/TLibEncoder/NALwrite.cpp                 |     2 +-
 source/Lib/TLibEncoder/TEncCu.cpp                   |    15 +-
 source/Lib/TLibEncoder/TEncCu.h                     |     2 +-
 source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp |     8 +-
 source/Lib/TLibEncoder/TEncSbac.cpp                 |    58 +-
 source/Lib/TLibEncoder/TEncSbac.h                   |     2 +-
 source/Lib/TLibEncoder/TEncSearch.cpp               |    98 +-
 source/Lib/TLibEncoder/TEncSearch.h                 |    15 +-
 source/common/CMakeLists.txt                        |    35 +-
 source/common/TShortYUV.cpp                         |     7 +-
 source/common/TShortYUV.h                           |     1 -
 source/common/common.cpp                            |    50 +-
 source/common/common.h                              |     1 -
 source/common/cpu.cpp                               |    88 +-
 source/common/intrapred.cpp                         |     4 +-
 source/common/ipfilter.cpp                          |   166 +--
 source/common/lowres.cpp                            |    16 +-
 source/common/lowres.h                              |     2 +-
 source/common/pixel.cpp                             |    28 +-
 source/common/primitives.cpp                        |    15 +-
 source/common/primitives.h                          |    30 +-
 source/common/threadpool.cpp                        |    83 +-
 source/common/vec/intra-sse41.cpp                   |     3 +-
 source/common/vec/intra-ssse3.cpp                   |     2 +-
 source/common/vec/ipfilter-sse41.cpp                |   257 ----
 source/common/vec/vec-primitives.cpp                |    11 +-
 source/common/x86/asm-primitives.cpp                |    99 +-
 source/common/x86/const-a.asm                       |     2 +
 source/common/x86/intrapred.h                       |    59 +-
 source/common/x86/intrapred8.asm                    |  1154 +++++++++++++++++++
 source/common/x86/ipfilter8.asm                     |   235 +--
 source/common/x86/ipfilter8.h                       |     1 -
 source/common/x86/mc-a.asm                          |  1032 ++++++++++++++++
 source/common/x86/pixel.h                           |    35 +
 source/common/x86/x86inc.asm                        |    58 +-
 source/encoder/CMakeLists.txt                       |    20 +-
 source/encoder/compress.cpp                         |    20 +-
 source/encoder/cturow.h                             |     2 +-
 source/encoder/dpb.cpp                              |     4 +-
 source/encoder/encoder.cpp                          |   144 +-
 source/encoder/encoder.h                            |     6 +
 source/encoder/frameencoder.cpp                     |    37 +-
 source/encoder/frameencoder.h                       |     1 +
 source/encoder/motion.cpp                           |     2 +-
 source/encoder/ratecontrol.cpp                      |    57 +-
 source/encoder/reference.cpp                        |     2 +-
 source/encoder/slicetype.cpp                        |   568 ++++-----
 source/encoder/slicetype.h                          |    11 +-
 source/encoder/weightPrediction.cpp                 |   108 +-
 source/encoder/weightPrediction.h                   |     2 +
 source/input/y4m.cpp                                |    80 +-
 source/input/yuv.cpp                                |     3 +
 source/test/intrapredharness.cpp                    |     7 +-
 source/test/ipfilterharness.cpp                     |   286 +---
 source/test/ipfilterharness.h                       |     5 +-
 source/test/mbdstharness.cpp                        |    28 +-
 source/test/pixelharness.cpp                        |    81 +-
 source/test/pixelharness.h                          |     1 +
 source/test/testharness.h                           |     1 +
 source/x265.cpp                                     |     7 +-
 source/x265.h                                       |    39 +-
 81 files changed, 3735 insertions(+), 2111 deletions(-)

diffs (truncated from 9263 to 300 lines):

diff -r edf64ac976ea -r f121e16811be source/CMakeLists.txt
--- a/source/CMakeLists.txt	Fri Jan 31 15:03:56 2014 -0600
+++ b/source/CMakeLists.txt	Mon Feb 03 23:33:36 2014 -0600
@@ -5,6 +5,10 @@ if(NOT CMAKE_BUILD_TYPE)
         "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
         FORCE)
 endif()
+message(STATUS "cmake version ${CMAKE_VERSION}")
+if(NOT CMAKE_VERSION VERSION_LESS "2.8.12.20131121")
+    cmake_policy(SET CMP0025 OLD) # report Apple's Clang as just Clang
+endif()
 
 project (x265)
 cmake_minimum_required (VERSION 2.8.8) # OBJECT libraries require 2.8.8
@@ -13,7 +17,7 @@ include(CheckFunctionExists)
 include(CheckCXXCompilerFlag)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 4)
+set(X265_BUILD 5)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
@@ -21,12 +25,36 @@ configure_file("${PROJECT_SOURCE_DIR}/x2
 
 SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
 
-if ("${CMAKE_SIZEOF_VOID_P}" MATCHES 8)
-    set(X64 1)
-    add_definitions(-DX86_64=1)
+# System architecture detection
+string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC)
+if("${SYSPROC}" STREQUAL "i386"   OR "${SYSPROC}" STREQUAL "amd64" OR
+   "${SYSPROC}" STREQUAL "x86_64" OR "${SYSPROC}" STREQUAL "x86"   OR
+   "${SYSPROC}" STREQUAL "")
+    message(STATUS "Detected x86 system processor")
+    set(X86 1)
+    add_definitions(-DX265_ARCH_X86=1)
+    if("${CMAKE_SIZEOF_VOID_P}" MATCHES 8)
+        set(X64 1)
+        add_definitions(-DX86_64=1)
+    endif()
+elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
+    message(STATUS "Detected ARM system processor")
+    set(ARM 1)
+    add_definitions(-DX265_ARCH_ARM=1)
+else()
+    message(STATUS "CMAKE_SYSTEM_PROCESSOR value `${CMAKE_SYSTEM_PROCESSOR}` is unknown")
+    message(STATUS "Please add this value near ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")
 endif()
 
-if (CMAKE_GENERATOR STREQUAL "Xcode")
+if(UNIX)
+    SET(PLATFORM_LIBS pthread)
+    if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+        SET(PLATFORM_LIBS ${PLATFORM_LIBS} rt)
+    endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+endif(UNIX)
+
+# Compiler detection
+if(CMAKE_GENERATOR STREQUAL "Xcode")
   set(XCODE 1)
 endif()
 if (APPLE)
@@ -92,8 +120,23 @@ if (GCC)
     if(X64 AND NOT WIN32)
         add_definitions(-fPIC)
     endif(X64 AND NOT WIN32)
+    if(X86 AND NOT X64)
+        add_definitions(-march=i686)
+    endif()
 endif(GCC)
 
+find_package(Yasm)
+if(YASM_FOUND AND X86)
+    if (YASM_VERSION_STRING VERSION_LESS "1.2.0")
+        message(STATUS "Yasm version ${YASM_VERSION_STRING} is too old. 1.2.0 or later required")
+        option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" OFF)
+    else()
+        message(STATUS "Found Yasm ${YASM_VERSION_STRING} to build assembly primitives")
+        option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" ON)
+    endif()
+endif()
+
+# Build options
 option(HIGH_BIT_DEPTH "Use 16bit pixels internally" OFF)
 if(HIGH_BIT_DEPTH)
     add_definitions(-DHIGH_BIT_DEPTH=1)
@@ -108,24 +151,6 @@ else(LOG_CU_STATISTICS)
     add_definitions(-DLOG_CU_STATISTICS=0)
 endif(LOG_CU_STATISTICS)
 
-find_package(Yasm)
-if(YASM_FOUND)
-    if (YASM_VERSION_STRING VERSION_LESS "1.2.0")
-        message(STATUS "Yasm version ${YASM_VERSION_STRING} is too old. 1.2.0 or later required")
-        option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" OFF)
-    else()
-        message(STATUS "Found Yasm ${YASM_VERSION_STRING} to build assembly primitives")
-        option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" ON)
-    endif()
-endif(YASM_FOUND)
-
-if(UNIX)
-    SET(PLATFORM_LIBS pthread)
-    if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
-        SET(PLATFORM_LIBS ${PLATFORM_LIBS} rt)
-    endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
-endif(UNIX)
-
 option(ENABLE_PPA "Enable PPA profiling instrumentation" OFF)
 if(ENABLE_PPA)
     add_definitions(-DENABLE_PPA)
@@ -154,8 +179,8 @@ endif()
 
 include(version) # determine X265_VERSION and X265_LATEST_TAG
 include_directories(. Lib common encoder "${PROJECT_BINARY_DIR}")
+add_subdirectory(encoder)
 add_subdirectory(common)
-add_subdirectory(encoder)
 
 if((MSVC_IDE OR XCODE) AND ENABLE_ASSEMBLY)
     # this is horrible. ugly, and hacky, and it reproduces logic found
diff -r edf64ac976ea -r f121e16811be source/Lib/TLibCommon/CommonDef.h
--- a/source/Lib/TLibCommon/CommonDef.h	Fri Jan 31 15:03:56 2014 -0600
+++ b/source/Lib/TLibCommon/CommonDef.h	Mon Feb 03 23:33:36 2014 -0600
@@ -139,7 +139,7 @@
 #define NOT_VALID                  -1
 
 // for use in HM, replaces old xMalloc/xFree macros
-#define X265_MALLOC(type, count)    x265_malloc(sizeof(type) * (count))
+#define X265_MALLOC(type, count)    (type*)x265_malloc(sizeof(type) * (count))
 #define X265_FREE(ptr)              x265_free(ptr)
 
 // ====================================================================================================================
diff -r edf64ac976ea -r f121e16811be source/Lib/TLibCommon/ContextTables.h
--- a/source/Lib/TLibCommon/ContextTables.h	Fri Jan 31 15:03:56 2014 -0600
+++ b/source/Lib/TLibCommon/ContextTables.h	Mon Feb 03 23:33:36 2014 -0600
@@ -48,16 +48,13 @@
 // Constants
 // ====================================================================================================================
 
-#define MAX_NUM_CTX_MOD             256       ///< maximum number of supported contexts
-
 #define NUM_SPLIT_FLAG_CTX            3       ///< number of context models for split flag
 #define NUM_SKIP_FLAG_CTX             3       ///< number of context models for skip flag
 
 #define NUM_MERGE_FLAG_EXT_CTX        1       ///< number of context models for merge flag of merge extended
 #define NUM_MERGE_IDX_EXT_CTX         1       ///< number of context models for merge index of merge extended
 
-#define NUM_PART_SIZE_CTX             3       ///< number of context models for partition size
-#define NUM_CU_AMP_CTX                1       ///< number of context models for partition size (AMP)
+#define NUM_PART_SIZE_CTX             4       ///< number of context models for partition size
 #define NUM_PRED_MODE_CTX             1       ///< number of context models for prediction mode
 
 #define NUM_ADI_CTX                   1       ///< number of context models for intra prediction
@@ -68,7 +65,7 @@
 
 #define NUM_REF_NO_CTX                2       ///< number of context models for reference index
 #define NUM_TRANS_SUBDIV_FLAG_CTX     3       ///< number of context models for transform subdivision flags
-#define NUM_QT_CBF_CTX                4       ///< number of context models for QT CBF
+#define NUM_QT_CBF_CTX                6       ///< number of context models for QT CBF
 #define NUM_QT_ROOT_CBF_CTX           1       ///< number of context models for QT ROOT CBF
 #define NUM_DELTA_QP_CTX              3       ///< number of context models for dQP
 
@@ -78,7 +75,9 @@
 #define NUM_SIG_FLAG_CTX_LUMA         27      ///< number of context models for luma sig flag
 #define NUM_SIG_FLAG_CTX_CHROMA       15      ///< number of context models for chroma sig flag
 
-#define NUM_CTX_LAST_FLAG_XY          15      ///< number of context models for last coefficient position
+#define NUM_CTX_LAST_FLAG_XY          18      ///< number of context models for last coefficient position
+#define NUM_CTX_LAST_FLAG_XY_LUMA     15      ///< number of context models for last coefficient position of luma
+#define NUM_CTX_LAST_FLAG_XY_CHROMA    3      ///< number of context models for last coefficient position of chroma
 
 #define NUM_ONE_FLAG_CTX              24      ///< number of context models for greater than 1 flag
 #define NUM_ONE_FLAG_CTX_LUMA         16      ///< number of context models for greater than 1 flag of luma
@@ -87,7 +86,7 @@
 #define NUM_ABS_FLAG_CTX_LUMA          4      ///< number of context models for greater than 2 flag of luma
 #define NUM_ABS_FLAG_CTX_CHROMA        2      ///< number of context models for greater than 2 flag of chroma
 
-#define NUM_MVP_IDX_CTX               2       ///< number of context models for MVP index
+#define NUM_MVP_IDX_CTX               1       ///< number of context models for MVP index
 
 #define NUM_SAO_MERGE_FLAG_CTX        1       ///< number of context models for SAO merge flags
 #define NUM_SAO_TYPE_IDX_CTX          1       ///< number of context models for SAO type index
@@ -110,17 +109,16 @@
 #define OFF_REF_NO_CTX                      (OFF_INTER_DIR_CTX          +     NUM_INTER_DIR_CTX)
 #define OFF_MV_RES_CTX                      (OFF_REF_NO_CTX             +     NUM_REF_NO_CTX)
 #define OFF_QT_CBF_CTX                      (OFF_MV_RES_CTX             +     NUM_MV_RES_CTX)
-#define OFF_TRANS_SUBDIV_FLAG_CTX           (OFF_QT_CBF_CTX             + 2 * NUM_QT_CBF_CTX)
+#define OFF_TRANS_SUBDIV_FLAG_CTX           (OFF_QT_CBF_CTX             +     NUM_QT_CBF_CTX)
 #define OFF_QT_ROOT_CBF_CTX                 (OFF_TRANS_SUBDIV_FLAG_CTX  +     NUM_TRANS_SUBDIV_FLAG_CTX)
 #define OFF_SIG_CG_FLAG_CTX                 (OFF_QT_ROOT_CBF_CTX        +     NUM_QT_ROOT_CBF_CTX)
 #define OFF_SIG_FLAG_CTX                    (OFF_SIG_CG_FLAG_CTX        + 2 * NUM_SIG_CG_FLAG_CTX)
 #define OFF_CTX_LAST_FLAG_X                 (OFF_SIG_FLAG_CTX           +     NUM_SIG_FLAG_CTX)
-#define OFF_CTX_LAST_FLAG_Y                 (OFF_CTX_LAST_FLAG_X        + 2 * NUM_CTX_LAST_FLAG_XY)
-#define OFF_ONE_FLAG_CTX                    (OFF_CTX_LAST_FLAG_Y        + 2 * NUM_CTX_LAST_FLAG_XY)
+#define OFF_CTX_LAST_FLAG_Y                 (OFF_CTX_LAST_FLAG_X        +     NUM_CTX_LAST_FLAG_XY)
+#define OFF_ONE_FLAG_CTX                    (OFF_CTX_LAST_FLAG_Y        +     NUM_CTX_LAST_FLAG_XY)
 #define OFF_ABS_FLAG_CTX                    (OFF_ONE_FLAG_CTX           +     NUM_ONE_FLAG_CTX)
 #define OFF_MVP_IDX_CTX                     (OFF_ABS_FLAG_CTX           +     NUM_ABS_FLAG_CTX)
-#define OFF_CU_AMP_CTX                      (OFF_MVP_IDX_CTX            +     NUM_MVP_IDX_CTX)
-#define OFF_SAO_MERGE_FLAG_CTX              (OFF_CU_AMP_CTX             +     NUM_CU_AMP_CTX)
+#define OFF_SAO_MERGE_FLAG_CTX              (OFF_MVP_IDX_CTX            +     NUM_MVP_IDX_CTX)
 #define OFF_SAO_TYPE_IDX_CTX                (OFF_SAO_MERGE_FLAG_CTX     +     NUM_SAO_MERGE_FLAG_CTX)
 #define OFF_TRANSFORMSKIP_FLAG_CTX          (OFF_SAO_TYPE_IDX_CTX       +     NUM_SAO_TYPE_IDX_CTX)
 #define OFF_CU_TRANSQUANT_BYPASS_FLAG_CTX   (OFF_TRANSFORMSKIP_FLAG_CTX + 2 * NUM_TRANSFORMSKIP_FLAG_CTX)
@@ -157,7 +155,6 @@ uint8_t sbacInit(int qp, int initValue);
 // Tables
 // ====================================================================================================================
 
-
 // initial probability for cu_transquant_bypass flag
 static const uint8_t
     INIT_CU_TRANSQUANT_BYPASS_FLAG[3][NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX] =
@@ -203,17 +200,9 @@ static const uint8_t
 static const uint8_t
     INIT_PART_SIZE[3][NUM_PART_SIZE_CTX] =
 {
-    { 154,  139,  CNU, },
-    { 154,  139,  CNU, },
-    { 184,  CNU,  CNU, },
-};
-
-static const uint8_t
-    INIT_CU_AMP_POS[3][NUM_CU_AMP_CTX] =
-{
-    { 154, },
-    { 154, },
-    { CNU, },
+    { 154,  139,  154, 154 },
+    { 154,  139,  154, 154 },
+    { 184,  CNU,  CNU, CNU },
 };
 
 static const uint8_t
@@ -273,11 +262,11 @@ static const uint8_t
 };
 
 static const uint8_t
-    INIT_QT_CBF[3][2 * NUM_QT_CBF_CTX] =
+    INIT_QT_CBF[3][NUM_QT_CBF_CTX] =
 {
-    { 153,  111,  CNU,  CNU,  149,   92,  167,  CNU, },
-    { 153,  111,  CNU,  CNU,  149,  107,  167,  CNU, },
-    { 111,  141,  CNU,  CNU,   94,  138,  182,  CNU, },
+    { 153,  111,  149,   92,  167,  154, },
+    { 153,  111,  149,  107,  167,  154, },
+    { 111,  141,   94,  138,  182,  154, },
 };
 
 static const uint8_t
@@ -289,14 +278,14 @@ static const uint8_t
 };
 
 static const uint8_t
-    INIT_LAST[3][2 * NUM_CTX_LAST_FLAG_XY] =
+    INIT_LAST[3][NUM_CTX_LAST_FLAG_XY] =
 {
     { 125,  110,  124,  110,   95,   94,  125,  111,  111,   79,  125,  126,  111,  111,   79,
-      108,  123,   93,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU, },
+      108,  123,   93 },
     { 125,  110,   94,  110,   95,   79,  125,  111,  110,   78,  110,  111,  111,   95,   94,
-      108,  123,  108,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU, },
+      108,  123,  108 },
     { 110,  110,  124,  125,  140,  153,  125,  127,  140,  109,  111,  143,  127,  111,   79,
-      108,  123,   63,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU,  CNU, },
+      108,  123,   63 },
 };
 
 static const uint8_t
@@ -337,9 +326,9 @@ static const uint8_t
 static const uint8_t
     INIT_MVP_IDX[3][NUM_MVP_IDX_CTX] =
 {
-    { 168,  CNU, },
-    { 168,  CNU, },
-    { CNU,  CNU, },
+    { 168 },
+    { 168 },
+    { CNU },
 };
 
 static const uint8_t
diff -r edf64ac976ea -r f121e16811be source/Lib/TLibCommon/TComBitStream.cpp
--- a/source/Lib/TLibCommon/TComBitStream.cpp	Fri Jan 31 15:03:56 2014 -0600
+++ b/source/Lib/TLibCommon/TComBitStream.cpp	Mon Feb 03 23:33:36 2014 -0600
@@ -53,7 +53,7 @@ using namespace x265;
 
 TComOutputBitstream::TComOutputBitstream()
 {
-    m_fifo = (uint8_t*)X265_MALLOC(uint8_t, MIN_FIFO_SIZE);
+    m_fifo = X265_MALLOC(uint8_t, MIN_FIFO_SIZE);
     clear();
 }
 
@@ -215,7 +215,7 @@ void TComOutputBitstream::push_back(uint
 
         /**  FIFO size is Reached into MIN_FIFO_SIZE then Reallocate the FIFO and Copy the fifo to new memory
         location and continue to push encoded bit streams */


More information about the x265-commits mailing list