Fix issues reported by valgrind in intra pred modules
Added a memset which is a potential fix to avoid the
access of uninitialized memory in intra pred modules.
BUG=aomedia:2752
Change-Id: Iaf1d81085994a634debe1165be3864a2cec3ee21
diff --git a/av1/common/reconintra.c b/av1/common/reconintra.c
index 2d68cca..c3b4665 100644
--- a/av1/common/reconintra.c
+++ b/av1/common/reconintra.c
@@ -35,6 +35,7 @@
#define INTRA_EDGE_FILT 3
#define INTRA_EDGE_TAPS 5
#define MAX_UPSAMPLE_SZ 16
+#define NUM_INTRA_NEIGHBOUR_PIXELS (MAX_TX_SIZE * 2 + 32)
static const uint8_t extend_modes[INTRA_MODES] = {
NEED_ABOVE | NEED_LEFT, // DC
@@ -1142,8 +1143,8 @@
int i;
uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
- DECLARE_ALIGNED(16, uint16_t, left_data[MAX_TX_SIZE * 2 + 32]);
- DECLARE_ALIGNED(16, uint16_t, above_data[MAX_TX_SIZE * 2 + 32]);
+ DECLARE_ALIGNED(16, uint16_t, left_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
+ DECLARE_ALIGNED(16, uint16_t, above_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
uint16_t *const above_row = above_data + 16;
uint16_t *const left_col = left_data + 16;
const int txwpx = tx_size_wide[tx_size];
@@ -1157,6 +1158,12 @@
const int is_dr_mode = av1_is_directional_mode(mode);
const int use_filter_intra = filter_intra_mode != FILTER_INTRA_MODES;
int base = 128 << (xd->bd - 8);
+ // The left_data, above_data buffers must be zeroed to fix some intermittent
+ // valgrind errors. Uninitialized reads in intra pred modules (e.g. width = 4
+ // path in av1_highbd_dr_prediction_z2_avx2()) from left_data, above_data are
+ // seen to be the potential reason for this issue.
+ aom_memset16(left_data, base + 1, NUM_INTRA_NEIGHBOUR_PIXELS);
+ aom_memset16(above_data, base - 1, NUM_INTRA_NEIGHBOUR_PIXELS);
// The default values if ref pixels are not available:
// base base-1 base-1 .. base-1 base-1 base-1 base-1 base-1 base-1
@@ -1200,7 +1207,7 @@
int need_bottom = extend_modes[mode] & NEED_BOTTOMLEFT;
if (use_filter_intra) need_bottom = 0;
if (is_dr_mode) need_bottom = p_angle > 180;
- const int num_left_pixels_needed = txhpx + (need_bottom ? txwpx : 3);
+ const int num_left_pixels_needed = txhpx + (need_bottom ? txwpx : 0);
i = 0;
if (n_left_px > 0) {
for (; i < n_left_px; i++) left_col[i] = left_ref[i * ref_stride];
@@ -1211,12 +1218,8 @@
}
if (i < num_left_pixels_needed)
aom_memset16(&left_col[i], left_col[i - 1], num_left_pixels_needed - i);
- } else {
- if (n_top_px > 0) {
- aom_memset16(left_col, above_ref[0], num_left_pixels_needed);
- } else {
- aom_memset16(left_col, base + 1, num_left_pixels_needed);
- }
+ } else if (n_top_px > 0) {
+ aom_memset16(left_col, above_ref[0], num_left_pixels_needed);
}
}
@@ -1238,12 +1241,8 @@
if (i < num_top_pixels_needed)
aom_memset16(&above_row[i], above_row[i - 1],
num_top_pixels_needed - i);
- } else {
- if (n_left_px > 0) {
- aom_memset16(above_row, left_ref[0], num_top_pixels_needed);
- } else {
- aom_memset16(above_row, base - 1, num_top_pixels_needed);
- }
+ } else if (n_left_px > 0) {
+ aom_memset16(above_row, left_ref[0], num_top_pixels_needed);
}
}
@@ -1330,8 +1329,8 @@
int i;
const uint8_t *above_ref = ref - ref_stride;
const uint8_t *left_ref = ref - 1;
- DECLARE_ALIGNED(16, uint8_t, left_data[MAX_TX_SIZE * 2 + 32]);
- DECLARE_ALIGNED(16, uint8_t, above_data[MAX_TX_SIZE * 2 + 32]);
+ DECLARE_ALIGNED(16, uint8_t, left_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
+ DECLARE_ALIGNED(16, uint8_t, above_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
uint8_t *const above_row = above_data + 16;
uint8_t *const left_col = left_data + 16;
const int txwpx = tx_size_wide[tx_size];
@@ -1342,6 +1341,12 @@
int p_angle = 0;
const int is_dr_mode = av1_is_directional_mode(mode);
const int use_filter_intra = filter_intra_mode != FILTER_INTRA_MODES;
+ // The left_data, above_data buffers must be zeroed to fix some intermittent
+ // valgrind errors. Uninitialized reads in intra pred modules (e.g. width = 4
+ // path in av1_dr_prediction_z1_avx2()) from left_data, above_data are seen to
+ // be the potential reason for this issue.
+ memset(left_data, 129, NUM_INTRA_NEIGHBOUR_PIXELS);
+ memset(above_data, 127, NUM_INTRA_NEIGHBOUR_PIXELS);
// The default values if ref pixels are not available:
// 128 127 127 .. 127 127 127 127 127 127
@@ -1386,10 +1391,7 @@
int need_bottom = extend_modes[mode] & NEED_BOTTOMLEFT;
if (use_filter_intra) need_bottom = 0;
if (is_dr_mode) need_bottom = p_angle > 180;
- // the avx2 dr_prediction_z2 may read at most 3 extra bytes,
- // due to the avx2 mask load is with dword granularity.
- // so we initialize 3 extra bytes to silence valgrind complain.
- const int num_left_pixels_needed = txhpx + (need_bottom ? txwpx : 3);
+ const int num_left_pixels_needed = txhpx + (need_bottom ? txwpx : 0);
i = 0;
if (n_left_px > 0) {
for (; i < n_left_px; i++) left_col[i] = left_ref[i * ref_stride];
@@ -1400,12 +1402,8 @@
}
if (i < num_left_pixels_needed)
memset(&left_col[i], left_col[i - 1], num_left_pixels_needed - i);
- } else {
- if (n_top_px > 0) {
- memset(left_col, above_ref[0], num_left_pixels_needed);
- } else {
- memset(left_col, 129, num_left_pixels_needed);
- }
+ } else if (n_top_px > 0) {
+ memset(left_col, above_ref[0], num_left_pixels_needed);
}
}
@@ -1425,12 +1423,8 @@
}
if (i < num_top_pixels_needed)
memset(&above_row[i], above_row[i - 1], num_top_pixels_needed - i);
- } else {
- if (n_left_px > 0) {
- memset(above_row, left_ref[0], num_top_pixels_needed);
- } else {
- memset(above_row, 127, num_top_pixels_needed);
- }
+ } else if (n_left_px > 0) {
+ memset(above_row, left_ref[0], num_top_pixels_needed);
}
}