mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 14:34:33 +02:00
harness some malloc/calloc to use WebPSafeMalloc and WebPSafeCalloc
quite a large security sweep. Change-Id: If150dfbb46e6e9b56210473a109c8ad6ccd0cea4
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "./color_cache.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
@ -24,7 +25,8 @@ int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
|
||||
const int hash_size = 1 << hash_bits;
|
||||
assert(cc != NULL);
|
||||
assert(hash_bits > 0);
|
||||
cc->colors_ = (uint32_t*)calloc(hash_size, sizeof(*cc->colors_));
|
||||
cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size,
|
||||
sizeof(*cc->colors_));
|
||||
if (cc->colors_ == NULL) return 0;
|
||||
cc->hash_shift_ = 32 - hash_bits;
|
||||
return 1;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "./huffman.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "../webp/format_constants.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
@ -49,8 +50,8 @@ static int TreeInit(HuffmanTree* const tree, int num_leaves) {
|
||||
// Note that a Huffman tree is a full binary tree; and in a full binary tree
|
||||
// with L leaves, the total number of nodes N = 2 * L - 1.
|
||||
tree->max_nodes_ = 2 * num_leaves - 1;
|
||||
tree->root_ =
|
||||
(HuffmanTreeNode*)malloc(tree->max_nodes_ * sizeof(*tree->root_));
|
||||
tree->root_ = (HuffmanTreeNode*)WebPSafeMalloc((uint64_t)tree->max_nodes_,
|
||||
sizeof(*tree->root_));
|
||||
if (tree->root_ == NULL) return 0;
|
||||
TreeNodeInit(tree->root_); // Initialize root.
|
||||
tree->num_nodes_ = 1;
|
||||
@ -173,7 +174,8 @@ int HuffmanTreeBuildImplicit(HuffmanTree* const tree,
|
||||
int ok = 0;
|
||||
|
||||
// Get Huffman codes from the code lengths.
|
||||
int* const codes = (int*)malloc(code_lengths_size * sizeof(*codes));
|
||||
int* const codes =
|
||||
(int*)WebPSafeMalloc((uint64_t)code_lengths_size, sizeof(*codes));
|
||||
if (codes == NULL) goto End;
|
||||
|
||||
if (!HuffmanCodeLengthsToCodes(code_lengths, code_lengths_size, codes)) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "./huffman_encode.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "../webp/format_constants.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -196,7 +197,7 @@ static int GenerateOptimalTree(const int* const histogram, int histogram_size,
|
||||
// population and all the inserted nodes combining two existing nodes.
|
||||
// The tree pool needs 2 * (tree_size_orig - 1) entities, and the
|
||||
// tree needs exactly tree_size_orig entities.
|
||||
tree = (HuffmanTree*)malloc(3 * tree_size_orig * sizeof(*tree));
|
||||
tree = (HuffmanTree*)WebPSafeMalloc(3ULL * tree_size_orig, sizeof(*tree));
|
||||
if (tree == NULL) return 0;
|
||||
tree_pool = tree + tree_size_orig;
|
||||
|
||||
|
Reference in New Issue
Block a user