04_clamp-index-values-to-fix-index-overflow-in-IMA.cpp.patch 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. From: Antonio Larrosa <larrosa@kde.org>
  2. Date: Mon, 6 Mar 2017 18:02:31 +0100
  3. Subject: clamp index values to fix index overflow in IMA.cpp
  4. This fixes #33
  5. (also reported at https://bugzilla.opensuse.org/show_bug.cgi?id=1026981
  6. and https://blogs.gentoo.org/ago/2017/02/20/audiofile-global-buffer-overflow-in-decodesample-ima-cpp/)
  7. ---
  8. libaudiofile/modules/IMA.cpp | 4 ++--
  9. 1 file changed, 2 insertions(+), 2 deletions(-)
  10. diff --git a/libaudiofile/modules/IMA.cpp b/libaudiofile/modules/IMA.cpp
  11. index 7476d44..df4aad6 100644
  12. --- a/libaudiofile/modules/IMA.cpp
  13. +++ b/libaudiofile/modules/IMA.cpp
  14. @@ -169,7 +169,7 @@ int IMA::decodeBlockWAVE(const uint8_t *encoded, int16_t *decoded)
  15. if (encoded[1] & 0x80)
  16. m_adpcmState[c].previousValue -= 0x10000;
  17. - m_adpcmState[c].index = encoded[2];
  18. + m_adpcmState[c].index = clamp(encoded[2], 0, 88);
  19. *decoded++ = m_adpcmState[c].previousValue;
  20. @@ -210,7 +210,7 @@ int IMA::decodeBlockQT(const uint8_t *encoded, int16_t *decoded)
  21. predictor -= 0x10000;
  22. state.previousValue = clamp(predictor, MIN_INT16, MAX_INT16);
  23. - state.index = encoded[1] & 0x7f;
  24. + state.index = clamp(encoded[1] & 0x7f, 0, 88);
  25. encoded += 2;
  26. for (int n=0; n<m_framesPerPacket; n+=2)