Browse Source

!2858 JPEG decoder hangs if the image is sliced to 3 bytes

Merge pull request !2858 from h.farahat/slice_jpeg
tags/v0.6.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
b967997554
3 changed files with 5 additions and 5 deletions
  1. +3
    -3
      mindspore/ccsrc/dataset/kernels/image/image_utils.cc
  2. +1
    -1
      mindspore/ccsrc/dataset/kernels/image/image_utils.h
  3. +1
    -1
      mindspore/ccsrc/dataset/kernels/image/random_crop_decode_resize_op.cc

+ 3
- 3
mindspore/ccsrc/dataset/kernels/image/image_utils.cc View File

@@ -121,14 +121,14 @@ Status Resize(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *out
}
}

bool HasJpegMagic(const std::shared_ptr<Tensor> &input) {
bool IsNonEmptyJPEG(const std::shared_ptr<Tensor> &input) {
const unsigned char *kJpegMagic = (unsigned char *)"\xFF\xD8\xFF";
constexpr size_t kJpegMagicLen = 3;
return input->SizeInBytes() >= kJpegMagicLen && memcmp(input->GetBuffer(), kJpegMagic, kJpegMagicLen) == 0;
return input->SizeInBytes() > kJpegMagicLen && memcmp(input->GetBuffer(), kJpegMagic, kJpegMagicLen) == 0;
}

Status Decode(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
if (HasJpegMagic(input)) {
if (IsNonEmptyJPEG(input)) {
return JpegCropAndDecode(input, output);
} else {
return DecodeCv(input, output);


+ 1
- 1
mindspore/ccsrc/dataset/kernels/image/image_utils.h View File

@@ -96,7 +96,7 @@ Status Decode(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *out

Status DecodeCv(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output);

bool HasJpegMagic(const std::shared_ptr<Tensor> &input);
bool IsNonEmptyJPEG(const std::shared_ptr<Tensor> &input);

void JpegSetSource(j_decompress_ptr c_info, const void *data, int64_t data_size);



+ 1
- 1
mindspore/ccsrc/dataset/kernels/image/random_crop_decode_resize_op.cc View File

@@ -31,7 +31,7 @@ Status RandomCropDecodeResizeOp::Compute(const std::shared_ptr<Tensor> &input, s
if (input == nullptr) {
RETURN_STATUS_UNEXPECTED("input tensor is null");
}
if (!HasJpegMagic(input)) {
if (!IsNonEmptyJPEG(input)) {
DecodeOp op(true);
std::shared_ptr<Tensor> decoded;
RETURN_IF_NOT_OK(op.Compute(input, &decoded));


Loading…
Cancel
Save