Fix OOB write in BuildHuffmanTable.

First, BuildHuffmanTable is called to check if the data is valid.
If it is and the table is not big enough, more memory is allocated.

This will make sure that valid (but unoptimized because of unbalanced
codes) streams are still decodable.

Bug: 299477569
Bug: chromium:1479274
(cherry picked from commit 902bc9190331343b2017211debcec8d2ab87e17a)
(cherry picked from commit 2af26267cdfcb63a88e5c74a85927a12d6ca1d76)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3acf2aa5c074d5659c386c4462059b78489030e0)
Merged-In: Iaf8c74fe2b67925a577385be521791da42d47339
Change-Id: Iaf8c74fe2b67925a577385be521791da42d47339
5 files changed