Prevent overread when decoding malformed JPEG

The accelerated Huffman decoder was previously invoked if there were
> 128 bytes in the input buffer.  However, it is possible to construct a
JPEG image with Huffman blocks > 430 bytes in length
(http://stackoverflow.com/questions/2734678/jpeg-calculating-max-size).
While such images are pathological and could never be created by a
JPEG compressor, it is conceivable that an attacker could use such an
artifially-constructed image to trigger an input buffer overrun in the
libjpeg-turbo decompressor and thus gain access to some of the data on
the calling program's heap.

This patch simply increases the minimum buffer size for the accelerated
Huffman decoder to 512 bytes, which should (hopefully) accommodate any
possible input.

This addresses a major issue (LJT-01-005) identified in a security audit
by Cure53.

Cherry picked from upstream:
https://github.com/libjpeg-turbo/libjpeg-turbo/commit/0463f7c9aad060fcd56e98d025ce16185279e2bc

BUG:27494207
BUG:27480923

Change-Id: I94876fecafa8b7d7f31734cb21d2ca0f382802ec
3 files changed
tree: e52c4619dabf23cb6e2f7be3678a4d5719e081b4
  1. cmakescripts/
  2. doc/
  3. java/
  4. md5/
  5. release/
  6. sharedlib/
  7. simd/
  8. testimages/
  9. win/
  10. .gitignore
  11. acinclude.m4
  12. Android.mk
  13. bmp.c
  14. bmp.h
  15. BUILDING.txt
  16. cderror.h
  17. cdjpeg.c
  18. cdjpeg.h
  19. change.log
  20. ChangeLog.txt
  21. cjpeg.1
  22. cjpeg.c
  23. CMakeLists.txt
  24. coderules.txt
  25. configure.ac
  26. djpeg.1
  27. djpeg.c
  28. doxygen-extra.css
  29. doxygen.config
  30. example.c
  31. jaricom.c
  32. jcapimin.c
  33. jcapistd.c
  34. jcarith.c
  35. jccoefct.c
  36. jccolext.c
  37. jccolor.c
  38. jcdctmgr.c
  39. jchuff.c
  40. jchuff.h
  41. jcinit.c
  42. jcmainct.c
  43. jcmarker.c
  44. jcmaster.c
  45. jcomapi.c
  46. jconfig.h
  47. jconfig.txt
  48. jconfigint.h
  49. jcparam.c
  50. jcphuff.c
  51. jcprepct.c
  52. jcsample.c
  53. jcstest.c
  54. jctrans.c
  55. jdapimin.c
  56. jdapistd.c
  57. jdarith.c
  58. jdatadst-tj.c
  59. jdatadst.c
  60. jdatasrc-tj.c
  61. jdatasrc.c
  62. jdcoefct.c
  63. jdcoefct.h
  64. jdcol565.c
  65. jdcolext.c
  66. jdcolor.c
  67. jdct.h
  68. jddctmgr.c
  69. jdhuff.c
  70. jdhuff.h
  71. jdinput.c
  72. jdmainct.c
  73. jdmainct.h
  74. jdmarker.c
  75. jdmaster.c
  76. jdmaster.h
  77. jdmerge.c
  78. jdmrg565.c
  79. jdmrgext.c
  80. jdphuff.c
  81. jdpostct.c
  82. jdsample.c
  83. jdsample.h
  84. jdtrans.c
  85. jerror.c
  86. jerror.h
  87. jfdctflt.c
  88. jfdctfst.c
  89. jfdctint.c
  90. jidctflt.c
  91. jidctfst.c
  92. jidctint.c
  93. jidctred.c
  94. jinclude.h
  95. jmemmgr.c
  96. jmemnobs.c
  97. jmemsys.h
  98. jmorecfg.h
  99. jpeg_nbits_table.h
  100. jpegcomp.h
  101. jpegint.h
  102. jpeglib.h
  103. jpegtran.1
  104. jpegtran.c
  105. jquant1.c
  106. jquant2.c
  107. jsimd.h
  108. jsimd_none.c
  109. jsimddct.h
  110. jstdhuff.c
  111. jutils.c
  112. jversion.h
  113. libjpeg.map.in
  114. libjpeg.txt
  115. LICENSE.txt
  116. Makefile.am
  117. rdbmp.c
  118. rdcolmap.c
  119. rdgif.c
  120. rdjpgcom.1
  121. rdjpgcom.c
  122. rdppm.c
  123. rdrle.c
  124. rdswitch.c
  125. rdtarga.c
  126. README
  127. README-turbo.txt
  128. README.android
  129. README.version
  130. structure.txt
  131. tjbench.c
  132. tjbenchtest.in
  133. tjbenchtest.java.in
  134. tjexampletest.in
  135. tjunittest.c
  136. tjutil.c
  137. tjutil.h
  138. transupp.c
  139. transupp.h
  140. turbojpeg-jni.c
  141. turbojpeg-mapfile
  142. turbojpeg-mapfile.jni
  143. turbojpeg.c
  144. turbojpeg.h
  145. usage.txt
  146. wizard.txt
  147. wrbmp.c
  148. wrgif.c
  149. wrjpgcom.1
  150. wrjpgcom.c
  151. wrppm.c
  152. wrppm.h
  153. wrrle.c
  154. wrtarga.c