From 9440f969033b73e2e2a037c291bcb45619b1dfd1 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Thu, 11 Dec 2025 01:43:58 +0200 Subject: Reapply "Add more functionality to LLFile and cleanup LLAPRFile"" # Conflicts: # indra/llcrashlogger/llcrashlock.cpp # indra/llrender/llshadermgr.cpp # indra/test/CMakeLists.txt --- indra/newview/llviewerassetupload.cpp | 39 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'indra/newview/llviewerassetupload.cpp') diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp index 65a69acc88..5ac7d6b1fe 100644 --- a/indra/newview/llviewerassetupload.cpp +++ b/indra/newview/llviewerassetupload.cpp @@ -45,11 +45,7 @@ #include "llappviewer.h" #include "llviewerstats.h" #include "llfilesystem.h" -#include "llgesturemgr.h" -#include "llpreviewnotecard.h" -#include "llpreviewgesture.h" #include "llcoproceduremanager.h" -#include "llthread.h" #include "llkeyframemotion.h" #include "lldatapacker.h" #include "llvoavatarself.h" @@ -405,6 +401,7 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile() std::string errorMessage; std::string errorLabel; + std::error_code ec; bool error = false; @@ -475,30 +472,38 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile() error = true; // read from getFileName() - LLAPRFile infile; - infile.open(getFileName(),LL_APR_RB); - if (!infile.getFileHandle()) + LLFile infile(getFileName(), LLFile::in | LLFile::binary, ec); + if (ec || !infile) { LL_WARNS() << "Couldn't open file for reading: " << getFileName() << LL_ENDL; errorMessage = llformat("Failed to open animation file %s\n", getFileName().c_str()); } else { - S32 size = LLAPRFile::size(getFileName()); + S64 size = infile.size(ec); + if (ec || size <= 0) + { + LLError::LLUserWarningMsg::showMissingFiles(); + LL_ERRS() << "Invalid file" << LL_ENDL; + } + else if (size > INT_MAX) + { + LL_ERRS() << "File is too big, size: " << size << LL_ENDL; + } U8* buffer = new(std::nothrow) U8[size]; if (!buffer) { LLError::LLUserWarningMsg::showOutOfMemory(); LL_ERRS() << "Bad memory allocation for buffer, size: " << size << LL_ENDL; } - S32 size_read = infile.read(buffer,size); - if (size_read != size) + S64 size_read = infile.read(buffer, size, ec); + if (ec || size_read != size) { errorMessage = llformat("Failed to read animation file %s: wanted %d bytes, got %d\n", getFileName().c_str(), size, size_read); } else { - LLDataPackerBinaryBuffer dp(buffer, size); + LLDataPackerBinaryBuffer dp(buffer, (S32)size); LLKeyframeMotion *motionp = new LLKeyframeMotion(getAssetId()); motionp->setCharacter(gAgentAvatarp); if (motionp->deserialize(dp, getAssetId(), false)) @@ -544,18 +549,17 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile() setAssetType(assetType); // copy this file into the cache for upload - S32 file_size; - LLAPRFile infile; - infile.open(filename, LL_APR_RB, NULL, &file_size); - if (infile.getFileHandle()) + LLFile infile(filename, LLFile::in | LLFile::binary, ec); + if (!ec && infile.size(ec) > 0) { LLFileSystem file(getAssetId(), assetType, LLFileSystem::APPEND); + S64 read_bytes; const S32 buf_size = 65536; U8 copy_buf[buf_size]; - while ((file_size = infile.read(copy_buf, buf_size))) + while (((read_bytes = infile.read(copy_buf, buf_size, ec))) > 0) { - file.write(copy_buf, file_size); + file.write(copy_buf, (S32)read_bytes); } } else @@ -569,7 +573,6 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile() } return LLSD(); - } //========================================================================= -- cgit v1.3 From 43cdddd715ff71ddc447c1d47f5d4f3868ecafb4 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Wed, 17 Dec 2025 17:27:47 +0200 Subject: #4899 Fix erros related to negative file size --- indra/llcharacter/llkeyframemotion.cpp | 2 +- indra/llcommon/llfile.cpp | 6 ++++-- indra/llcommon/llfile.h | 4 ++-- indra/newview/llviewerassetupload.cpp | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'indra/newview/llviewerassetupload.cpp') diff --git a/indra/llcharacter/llkeyframemotion.cpp b/indra/llcharacter/llkeyframemotion.cpp index be1c74a908..4e5a920230 100644 --- a/indra/llcharacter/llkeyframemotion.cpp +++ b/indra/llcharacter/llkeyframemotion.cpp @@ -589,7 +589,7 @@ LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *charact } else { - LL_WARNS() << "Failed to allocate buffer: " << anim_file_size << mID << LL_ENDL; + LL_WARNS() << "Failed to allocate buffer: " << anim_file_size << " " << mID << LL_ENDL; } delete anim_file; anim_file = NULL; diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index ec4e15c690..0ceb2eb03b 100755 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -564,7 +564,8 @@ S64 LLFile::size(std::error_code& ec) return statval.st_size; } #endif - return set_ec_from_system_error(ec); + set_ec_from_system_error(ec); + return 0; } S64 LLFile::tell(std::error_code& ec) @@ -1070,7 +1071,8 @@ S64 LLFile::size(const std::string& filename, int suppress_warning) std::intmax_t size = static_cast(std::filesystem::file_size(file_path, ec)); if (ec) { - return warnif("size", filename, ec, suppress_warning); + warnif("size", filename, ec, suppress_warning); + return 0; } return size; } diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h index 0036e896c3..dcd561ce7f 100755 --- a/indra/llcommon/llfile.h +++ b/indra/llcommon/llfile.h @@ -203,7 +203,7 @@ public: /// Determine the size of the opened file S64 size(std::error_code& ec); - ///< @returns the number of bytes in the file or -1 on failure + ///< @returns the number of bytes in the file or 0 on failure /// Query the position of the current file pointer in the file S64 tell(std::error_code& ec); @@ -383,7 +383,7 @@ public: static S64 size(const std::string& filename, int suppress_warning = ENOENT); ///< we pass by default ENOENT in the optional 'suppress_warning' parameter to not spam /// the log with warnings when the file does not exist - /// @returns the file size on success or -1 on failure. + /// @returns the file size on success or 0 on failure. /// check if filename is an existing file or directory static bool exists(const std::string& filename); diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp index 5ac7d6b1fe..d93e900519 100644 --- a/indra/newview/llviewerassetupload.cpp +++ b/indra/newview/llviewerassetupload.cpp @@ -488,7 +488,7 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile() } else if (size > INT_MAX) { - LL_ERRS() << "File is too big, size: " << size << LL_ENDL; + LL_ERRS() << "File " << getFileName() << " is too big, size: " << size << LL_ENDL; } U8* buffer = new(std::nothrow) U8[size]; if (!buffer) -- cgit v1.3