encoder.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From 88fae6224b54ecf92ac6e3ae5083c3f352adc798 Mon Sep 17 00:00:00 2001
  2. From: Anuradha Suraparaju <anuradha@hoyle.rd.bbc.co.uk>
  3. Date: Fri, 17 Apr 2009 17:47:27 +1000
  4. Subject: [PATCH] Fix uninitialised memory read that causes the encoder to crash when using
  5. non-overlapping blocks.
  6. ---
  7. libdirac_common/mot_comp.cpp | 21 +++++++++++++++------
  8. 1 files changed, 15 insertions(+), 6 deletions(-)
  9. diff --git a/libdirac_common/mot_comp.cpp b/libdirac_common/mot_comp.cpp
  10. index aa8d37c..e0ec2ff 100644
  11. --- a/libdirac_common/mot_comp.cpp
  12. +++ b/libdirac_common/mot_comp.cpp
  13. @@ -306,6 +306,8 @@ void MotionCompensator::CompensateComponent( Picture* pic ,
  14. int save_from_row = m_bparams.Ybsep()-m_bparams.Yoffset();
  15. + bool row_overlap = ((m_bparams.Yblen() - m_bparams.Ybsep()) > 0);
  16. +
  17. // unpadded picture dimensions
  18. const int x_end_data = pic_data_out.FirstX() + std::min(pic_data_out.LengthX(), pic_size.x );
  19. const int y_end_data = pic_data_out.FirstY() + std::min(pic_data_out.LengthY(), pic_size.y );
  20. @@ -489,12 +491,19 @@ void MotionCompensator::CompensateComponent( Picture* pic ,
  21. //Increment the block vertical position
  22. pos.y += m_bparams.Ybsep();
  23. - // Copy the rows required to motion compensate the next row of block.
  24. - // This is usually Yblen-Ybsep rows.
  25. - memmove (pic_data[0], pic_data[save_from_row], (m_bparams.Yblen() - save_from_row)*pic_data.LengthX()*sizeof(ValueType));
  26. - memset( pic_data[m_bparams.Yblen() - save_from_row], 0, save_from_row*pic_data.LengthX()*sizeof(ValueType) );
  27. - save_from_row = m_bparams.Ybsep();
  28. -
  29. + if (row_overlap)
  30. + {
  31. + // Copy the rows required to motion compensate the next row of
  32. + // blocks. This is usually Yblen-Ybsep rows.
  33. + memmove (pic_data[0], pic_data[save_from_row], (m_bparams.Yblen() - save_from_row)*pic_data.LengthX()*sizeof(ValueType));
  34. + memset( pic_data[m_bparams.Yblen() - save_from_row], 0, save_from_row*pic_data.LengthX()*sizeof(ValueType) );
  35. + save_from_row = m_bparams.Ybsep();
  36. + }
  37. + else
  38. + {
  39. + // no row overlap. So reset pic_data to 0.
  40. + memset( pic_data[0], 0, m_bparams.Yblen()*pic_data.LengthX()*sizeof(ValueType) );
  41. + }
  42. }//yblock
  43. if ( m_add_or_sub == SUBTRACT)
  44. --
  45. 1.7.0.4