summaryrefslogtreecommitdiff
path: root/libavcodec/motion_est_template.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2006-12-12 13:31:12 +0000
committerMichael Niedermayer <michaelni@gmx.at>2006-12-12 13:31:12 +0000
commit2b0cdd9ec697164ac0415b8629c4a6e5ae9a3b8d (patch)
tree00e65fee716d610010bccf4cf84eb1fe4319c4f3 /libavcodec/motion_est_template.c
parent428cc588f222e4ea186bd54223e46cde40316215 (diff)
mv overflow in map fix (untested except regression tests)
Originally committed as revision 7287 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/motion_est_template.c')
-rw-r--r--libavcodec/motion_est_template.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c
index 5a01ef6222..28c637af88 100644
--- a/libavcodec/motion_est_template.c
+++ b/libavcodec/motion_est_template.c
@@ -823,20 +823,27 @@ static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
- for(j=i=0; i<ME_MAP_SIZE; i++){
+ /*Note j<MAX_SAB_SIZE is needed if MAX_SAB_SIZE < ME_MAP_SIZE as j can
+ become larger due to MVs overflowing their ME_MAP_MV_BITS bits space in map
+ */
+ for(j=i=0; i<ME_MAP_SIZE && j<MAX_SAB_SIZE; i++){
uint32_t key= map[i];
key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
- assert(j<MAX_SAB_SIZE); //max j = number of predictors
-
minima[j].height= score_map[i];
minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
+
+ // all entries in map should be in range except if the mv overflows their ME_MAP_MV_BITS bits space
+ if( minima[j].x > xmax || minima[j].x < xmin
+ || minima[j].y > ymax || minima[j].y < ymin)
+ continue;
+
minima[j].checked=0;
if(minima[j].x || minima[j].y)
minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;