Additional fixes

Added fix for overflow check
This commit is contained in:
Eric 2020-09-17 11:02:50 -04:00
parent a32b6f8abf
commit 43d4066aa0
3 changed files with 21 additions and 6 deletions

View File

@ -343,8 +343,12 @@ bool CenterCropOperation::ValidateParams() {
}
// We have to limit crop size due to library restrictions, optimized to only iterate over size_ once
for (int i = 0; i < size_.size(); ++i) {
if (size_[i] <= 0 || size_[i] == INT_MAX) {
MS_LOG(ERROR) << "Crop: invalid size, size must be greater than zero, got: " << size_[i];
if (size_[i] <= 0) {
MS_LOG(ERROR) << "CenterCrop: invalid size, size must be greater than 0, got: " << size_[i];
return false;
}
if (size_[i] == INT_MAX) {
MS_LOG(ERROR) << "CenterCrop: invalid size, size too large, got: " << size_[i];
return false;
}
}
@ -381,8 +385,12 @@ bool CropOperation::ValidateParams() {
}
// We have to limit crop size due to library restrictions, optimized to only iterate over size_ once
for (int i = 0; i < size_.size(); ++i) {
if (size_[i] <= 0 || size_[i] == INT_MAX) {
MS_LOG(ERROR) << "Crop: invalid size, size must be greater than zero, got: " << size_[i];
if (size_[i] <= 0) {
MS_LOG(ERROR) << "Crop: invalid size, size must be greater than 0, got: " << size_[i];
return false;
}
if (size_[i] == INT_MAX) {
MS_LOG(ERROR) << "Crop: invalid size, size too large, got: " << size_[i];
return false;
}
}
@ -490,7 +498,7 @@ bool NormalizeOperation::ValidateParams() {
}
// check std value
for (int i = 0; i < std_.size(); ++i) {
if (std_[i] < 0.0f || mean_[i] > 255.0f || CmpFloat(std_[i], 0.0f)) {
if (std_[i] < 0.0f || std_[i] > 255.0f || CmpFloat(std_[i], 0.0f)) {
MS_LOG(ERROR) << "Normalize: std vector has incorrect value: " << std_[i];
return false;
}

View File

@ -39,7 +39,6 @@ class AffineOp : public TensorOp {
static const std::vector<uint8_t> kFillValue;
/// Constructor
public:
explicit AffineOp(float_t degrees, const std::vector<float_t> &translation = kTranslation, float_t scale = kScale,
const std::vector<float_t> &shear = kShear, InterpolationMode interpolation = kDefInterpolation,
const std::vector<uint8_t> &fill_value = kFillValue);

View File

@ -352,6 +352,14 @@ Status Crop(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *outpu
if (input_cv->Rank() != 3 && input_cv->Rank() != 2) {
RETURN_STATUS_UNEXPECTED("Shape not <H,W,C> or <H,W>");
}
// account for integer overflow
if (y < 0 || (y + h) > input_cv->shape()[0] || (y + h) < 0) {
RETURN_STATUS_UNEXPECTED("Invalid y coordinate value for crop");
}
// account for integer overflow
if (x < 0 || (x + w) > input_cv->shape()[1] || (x + w) < 0) {
RETURN_STATUS_UNEXPECTED("Invalid x coordinate value for crop");
}
try {
TensorShape shape{h, w};
int num_channels = input_cv->shape()[2];