Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion torch_xla/csrc/ops/as_strided.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ absl::Status AsStrided::CheckSpecFitsInput(
absl::Status AsStrided::CheckSpecFitsInputImpl(
const xla::Shape& input_shape, int64_t input_element_count,
int64_t spec_element_count) const {
if (input_element_count < storage_offset_ + spec_element_count) {
if (storage_offset_ < 0 || spec_element_count < 0 ||
storage_offset_ > input_element_count ||
spec_element_count > input_element_count - storage_offset_) {
return XLA_ERROR_WITH_LOCATION(absl::InternalError(absl::StrCat(
"as_strided(): expected input ", input_shape.ToString(),
" (elements=", input_element_count,
Expand Down
4 changes: 3 additions & 1 deletion torch_xla/csrc/ops/as_strided_view_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ xla::XlaOp LowerAsStridedViewUpdate(xla::XlaOp target, xla::XlaOp input,
const xla::Shape& input_shape = ShapeHelper::ShapeOfXlaOp(input);
int64_t input_element_count = xla::ShapeUtil::ElementsIn(input_shape);
int64_t slice_size = torch_xla::runtime::util::Multiply<int64_t>(size);
XLA_CHECK_LE(storage_offset + input_element_count, slice_size);
XLA_CHECK_GE(storage_offset, 0);
XLA_CHECK_GE(input_element_count, 0);
XLA_CHECK_LE(storage_offset, slice_size - input_element_count);

std::vector<int64_t> permutation = GetDescendingOrderPermutation(stride);
xla::XlaOp transposed_input = xla::IsIdentityPermutation(permutation)
Expand Down
3 changes: 3 additions & 0 deletions torch_xla/csrc/runtime/stablehlo_composite_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ class BuildStableHLOCompositePass : public mlir::OperationPass<mlir::ModuleOp> {
if (json_value.empty()) {
return builder.getArrayAttr({});
}
if (json_value.size() > 1000000) {
return op->emitError() << "JSON array too large (max 1,000,000 elements)";
}
auto get_json_type = [](const json& j) {
auto ty = j.type();
if (ty == json::value_t::number_unsigned) {
Expand Down