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
Issue: FP3A13SEC-182
Issue: FP3-A13#249
Merged-In: I27c355c9970909fa5879e22e9f48b62acda386ef
Merged-In: I31c36dbf3aa78d35ecf38706b50464fd3d375741
Merged-In: Ic46c8cc324b1b2afe46f3a0d9d9b5205d92b2e18
(cherry picked from commit 902bc9190331343b2017211debcec8d2ab87e17a)
(cherry picked from commit 2af26267cdfcb63a88e5c74a85927a12d6ca1d76)
Change-Id: Iaf8c74fe2b67925a577385be521791da42d47339
5 files changed