diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp index 663d46fe38875f8b2f228c87369667d0687870aa..b930dc5147a7f58b507e6054ac71901ea6477105 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp @@ -73,11 +73,16 @@ static NError SendFileCore(FileInfo& srcFdg, FileInfo& destFdg, struct stat& sta int ret = 0; while (size > 0) { ret = uv_fs_sendfile(nullptr, sendfile_req.get(), destFdg.fdg->GetFD(), srcFdg.fdg->GetFD(), - offset, MAX_SIZE, nullptr); + offset, std::min(MAX_SIZE, size), nullptr); if (ret < 0) { HILOGE("Failed to sendfile by ret : %{public}d", ret); return NError(ret); } + if (static_cast(ret) > size) { + HILOGE("More bytes returned than the size of the file. The file size is %{public}d" \ + "The bytes returned is %{public}d", size, ret); + return NError(EIO); + } offset += static_cast(ret); size -= static_cast(ret); if (ret == 0) {