Advertisement
Guest User

A00-fix_segfault_w_gcc4.8.patch

a guest
May 20th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.03 KB | None | 0 0
  1. From 89aecb440e2939be7fb72d8362eb12504711b94f Mon Sep 17 00:00:00 2001
  2. From: Jason Garrett-Glaser <jason@x264.com>
  3. Date: Wed, 27 Feb 2013 13:30:22 -0800
  4. Subject: [PATCH 1/1] Fix array overreads that caused miscompilation in gcc
  5.  4.8
  6.  
  7. ---
  8. common/common.h  |    1 +
  9.  common/set.c     |   78 ++++++++++++++++++++++++++++++------------------------
  10.  tools/checkasm.c |    6 ++---
  11.  3 files changed, 47 insertions(+), 38 deletions(-)
  12.  
  13. diff --git a/common/common.h b/common/common.h
  14. index 39ad5cb..f5c69ba 100644
  15. --- a/common/common.h
  16. +++ b/common/common.h
  17. @@ -40,6 +40,7 @@
  18.  #define IS_DISPOSABLE(type) ( type == X264_TYPE_B )
  19.  #define FIX8(f) ((int)(f*(1<<8)+.5))
  20.  #define ALIGN(x,a) (((x)+((a)-1))&~((a)-1))
  21. +#define ARRAY_ELEMS(a) ((sizeof(a))/(sizeof(a[0])))
  22.  
  23.  #define CHECKED_MALLOC( var, size )\
  24.  do {\
  25. diff --git a/common/set.c b/common/set.c
  26. index 4c72125..fa8b158 100644
  27. --- a/common/set.c
  28. +++ b/common/set.c
  29. @@ -85,44 +85,49 @@ int x264_cqm_init( x264_t *h )
  30.      int max_qp_err = -1;
  31.      int max_chroma_qp_err = -1;
  32.      int min_qp_err = QP_MAX+1;
  33. -    int num_8x8_lists = h->sps->i_chroma_format_idc == CHROMA_444 ? 4 : 2; /* Checkasm may segfault if optimized out by --chroma-format */
  34. +    int num_8x8_lists = h->sps->i_chroma_format_idc == CHROMA_444 ? 4
  35. +                      : h->param.analyse.b_transform_8x8 ? 2 : 0; /* Checkasm may segfault if optimized out by --chroma-format */
  36.  
  37. -    for( int i = 0; i < 4 + num_8x8_lists; i++ )
  38. -    {
  39. -        int size = i<4 ? 16 : 64;
  40. -        int j;
  41. -        for( j = (i<4 ? 0 : 4); j < i; j++ )
  42. -            if( !memcmp( h->pps->scaling_list[i], h->pps->scaling_list[j], size*sizeof(uint8_t) ) )
  43. -                break;
  44. -        if( j < i )
  45. -        {
  46. -            h->  quant4_mf[i] = h->  quant4_mf[j];
  47. -            h->dequant4_mf[i] = h->dequant4_mf[j];
  48. -            h->unquant4_mf[i] = h->unquant4_mf[j];
  49. -        }
  50. -        else
  51. -        {
  52. -            CHECKED_MALLOC( h->  quant4_mf[i], (QP_MAX+1)*size*sizeof(udctcoef) );
  53. -            CHECKED_MALLOC( h->dequant4_mf[i],  6*size*sizeof(int) );
  54. -            CHECKED_MALLOC( h->unquant4_mf[i], (QP_MAX+1)*size*sizeof(int) );
  55. -        }
  56. -
  57. -        for( j = (i<4 ? 0 : 4); j < i; j++ )
  58. -            if( deadzone[j&3] == deadzone[i&3] &&
  59. -                !memcmp( h->pps->scaling_list[i], h->pps->scaling_list[j], size*sizeof(uint8_t) ) )
  60. -                break;
  61. -        if( j < i )
  62. -        {
  63. -            h->quant4_bias[i] = h->quant4_bias[j];
  64. -            h->quant4_bias0[i] = h->quant4_bias0[j];
  65. -        }
  66. -        else
  67. -        {
  68. -            CHECKED_MALLOC( h->quant4_bias[i], (QP_MAX+1)*size*sizeof(udctcoef) );
  69. -            CHECKED_MALLOC( h->quant4_bias0[i], (QP_MAX+1)*size*sizeof(udctcoef) );
  70. -        }
  71. +#define CQM_ALLOC( w, count )\
  72. +    for( int i = 0; i < count; i++ )\
  73. +    {\
  74. +        int size = w*w;\
  75. +        int start = w == 8 ? 4 : 0;\
  76. +        int j;\
  77. +        for( j = 0; j < i; j++ )\
  78. +            if( !memcmp( h->pps->scaling_list[i+start], h->pps->scaling_list[j+start], size*sizeof(uint8_t) ) )\
  79. +                break;\
  80. +        if( j < i )\
  81. +        {\
  82. +            h->  quant##w##_mf[i] = h->  quant##w##_mf[j];\
  83. +            h->dequant##w##_mf[i] = h->dequant##w##_mf[j];\
  84. +            h->unquant##w##_mf[i] = h->unquant##w##_mf[j];\
  85. +        }\
  86. +        else\
  87. +        {\
  88. +            CHECKED_MALLOC( h->  quant##w##_mf[i], (QP_MAX+1)*size*sizeof(udctcoef) );\
  89. +            CHECKED_MALLOC( h->dequant##w##_mf[i],  6*size*sizeof(int) );\
  90. +            CHECKED_MALLOC( h->unquant##w##_mf[i], (QP_MAX+1)*size*sizeof(int) );\
  91. +        }\
  92. +        for( j = 0; j < i; j++ )\
  93. +            if( deadzone[j] == deadzone[i] &&\
  94. +                !memcmp( h->pps->scaling_list[i+start], h->pps->scaling_list[j+start], size*sizeof(uint8_t) ) )\
  95. +                break;\
  96. +        if( j < i )\
  97. +        {\
  98. +            h->quant##w##_bias[i] = h->quant##w##_bias[j];\
  99. +            h->quant##w##_bias0[i] = h->quant##w##_bias0[j];\
  100. +        }\
  101. +        else\
  102. +        {\
  103. +            CHECKED_MALLOC( h->quant##w##_bias[i], (QP_MAX+1)*size*sizeof(udctcoef) );\
  104. +            CHECKED_MALLOC( h->quant##w##_bias0[i], (QP_MAX+1)*size*sizeof(udctcoef) );\
  105. +        }\
  106.      }
  107.  
  108. +    CQM_ALLOC( 4, 4 )
  109. +    CQM_ALLOC( 8, num_8x8_lists )
  110. +
  111.      for( int q = 0; q < 6; q++ )
  112.      {
  113.          for( int i = 0; i < 16; i++ )
  114. @@ -204,6 +209,9 @@ int x264_cqm_init( x264_t *h )
  115.          for( int cat = 0; cat < 3 + CHROMA444; cat++ )
  116.          {
  117.              int dct8x8 = cat&1;
  118. +            if( !h->param.analyse.b_transform_8x8 && dct8x8 )
  119. +                continue;
  120. +
  121.              int size = dct8x8 ? 64 : 16;
  122.              udctcoef *nr_offset = h->nr_offset_emergency[q][cat];
  123.              /* Denoise chroma first (due to h264's chroma QP offset), then luma, then DC. */
  124. diff --git a/tools/checkasm.c b/tools/checkasm.c
  125. index 9135b70..bbda21a 100644
  126. --- a/tools/checkasm.c
  127. +++ b/tools/checkasm.c
  128. @@ -309,7 +309,7 @@ static int check_pixel( int cpu_ref, int cpu_new )
  129.  
  130.  #define TEST_PIXEL( name, align ) \
  131.      ok = 1, used_asm = 0; \
  132. -    for( int i = 0; i < 8; i++ ) \
  133. +    for( int i = 0; i < ARRAY_ELEMS(pixel_c.name); i++ ) \
  134.      { \
  135.          int res_c, res_asm; \
  136.          if( pixel_asm.name[i] != pixel_ref.name[i] ) \
  137. @@ -1087,13 +1087,13 @@ static int check_dct( int cpu_ref, int cpu_new )
  138.      x264_zigzag_init( cpu_new, &zigzag_asm[0], &zigzag_asm[1] );
  139.  
  140.      ok = 1; used_asm = 0;
  141. -    TEST_INTERLEAVE( interleave_8x8_cavlc, level1, level2, dct1[0], 64 );
  142. +    TEST_INTERLEAVE( interleave_8x8_cavlc, level1, level2, dct8[0], 64 );
  143.      report( "zigzag_interleave :" );
  144.  
  145.      for( interlace = 0; interlace <= 1; interlace++ )
  146.      {
  147.          ok = 1; used_asm = 0;
  148. -        TEST_ZIGZAG_SCAN( scan_8x8, level1, level2, dct1[0], 8 );
  149. +        TEST_ZIGZAG_SCAN( scan_8x8, level1, level2, dct8[0], 8 );
  150.          TEST_ZIGZAG_SCAN( scan_4x4, level1, level2, dct1[0], 4 );
  151.          TEST_ZIGZAG_SUB( sub_4x4, level1, level2, 16 );
  152.          TEST_ZIGZAG_SUBAC( sub_4x4ac, level1, level2 );
  153. --
  154. 1.7.10.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement