Skip to content

Commit

Permalink
Check for nullptr return from malloc called from AllocateBuffers in L…
Browse files Browse the repository at this point in the history
…iteral.

PiperOrigin-RevId: 718967904
  • Loading branch information
Google-ML-Automation committed Jan 31, 2025
1 parent 3219006 commit b826949
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions xla/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ cc_library(
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:inlined_vector",
"@com_google_absl//absl/functional:function_ref",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
Expand Down
4 changes: 4 additions & 0 deletions xla/literal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ limitations under the License.
#include "absl/base/casts.h"
#include "absl/container/inlined_vector.h"
#include "absl/functional/function_ref.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
Expand Down Expand Up @@ -332,6 +333,9 @@ Literal LiteralBase::CreateFromShape(const Shape& shape) {
literal.root_piece_.ForEachMutableSubpiece(
[&](const ShapeIndex& index, Piece* piece) {
if (piece->subshape().IsArray()) {
CHECK_LE(piece->size_bytes_dense(),
1ULL * 1024 * 1024 * 1024) // 1 TB
<< "Literal size is too large";
memset(piece->untyped_data(), 0, piece->size_bytes_dense());
}
});
Expand Down

0 comments on commit b826949

Please sign in to comment.