mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 18:55:30 +00:00
17fc7463dd
The first check in ByteLengthIsValid() says "nsTArray only handles sizes up to INT32_MAX", but the actual requirement is that the capacity is no larger than UINT32_MAX. The check is overly restrictive if sizeof(E) is 1 byte, and overly permissive if sizeof(E) is greater than 2 bytes. I removed this check. Internal nsTArray invariants should be enforced by nsTArray methods. The second check is trying to check for overflow, but that should just be done using CheckedInt.
24 lines
674 B
C++
24 lines
674 B
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "IPCMessageUtils.h"
|
|
#include "mozilla/CheckedInt.h"
|
|
|
|
namespace IPC {
|
|
|
|
bool
|
|
ByteLengthIsValid(uint32_t aNumElements, size_t aElementSize, int* aByteLength)
|
|
{
|
|
auto length = CheckedInt<int>(aNumElements) * aElementSize;
|
|
if (!length.isValid()) {
|
|
return false;
|
|
}
|
|
*aByteLength = length.value();
|
|
return true;
|
|
}
|
|
|
|
} // namespace IPC
|