diff --git a/indra/llaudio/llaudiodecodemgr.cpp b/indra/llaudio/llaudiodecodemgr.cpp index 232b429130..59df3e5a66 100755 --- a/indra/llaudio/llaudiodecodemgr.cpp +++ b/indra/llaudio/llaudiodecodemgr.cpp @@ -130,6 +130,10 @@ S32 cache_seek(void *datasource, ogg_int64_t offset, S32 whence) break; case SEEK_END: origin = file->getSize(); + if (origin <= 0) + { + return -1; + } break; case SEEK_CUR: origin = -1; @@ -203,11 +207,11 @@ bool LLVorbisDecodeState::initDecode() { LL_WARNS("AudioEngine") << "unable to open vorbis source vfile for reading" << LL_ENDL; delete mInFilep; - mInFilep = NULL; + mInFilep = nullptr; return false; } - S32 r = ov_open_callbacks(mInFilep, &mVF, NULL, 0, cache_callbacks); + S32 r = ov_open_callbacks(mInFilep, &mVF, nullptr, 0, cache_callbacks); if(r < 0) { LL_WARNS("AudioEngine") << r << " Input to vorbis decode does not appear to be an Ogg bitstream: " << mUUID << LL_ENDL; @@ -259,7 +263,7 @@ bool LLVorbisDecodeState::initDecode() LL_WARNS("AudioEngine") << "Bad asset encoded by: " << comment->vendor << LL_ENDL; } delete mInFilep; - mInFilep = NULL; + mInFilep = nullptr; return false; } @@ -272,7 +276,7 @@ bool LLVorbisDecodeState::initDecode() { LL_WARNS("AudioEngine") << "Out of memory when trying to alloc buffer: " << size_guess << LL_ENDL; delete mInFilep; - mInFilep = NULL; + mInFilep = nullptr; return false; } diff --git a/indra/llcharacter/llkeyframemotion.cpp b/indra/llcharacter/llkeyframemotion.cpp index 4e5a920230..792d5dbd98 100644 --- a/indra/llcharacter/llkeyframemotion.cpp +++ b/indra/llcharacter/llkeyframemotion.cpp @@ -417,7 +417,6 @@ void LLKeyframeMotion::JointMotion::update(LLJointState* joint_state, F32 time, } } - //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // LLKeyframeMotion class @@ -564,59 +563,48 @@ LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *charact // Load named file by concatenating the character prefix with the motion name. // Load data into a buffer to be parsed. //------------------------------------------------------------------------- - U8 *anim_data; - S32 anim_file_size; - - bool success = false; - LLFileSystem* anim_file = new LLFileSystem(mID, LLAssetType::AT_ANIMATION); - if (!anim_file || !anim_file->getSize()) + S64 anim_file_size = LLFileSystem::getFileSize(mID, LLAssetType::AT_ANIMATION); + if (anim_file_size <= 0) { - delete anim_file; - anim_file = NULL; - // request asset over network on next call to load mAssetStatus = ASSET_NEEDS_FETCH; return STATUS_HOLD; } - else + + U8 *anim_data = new(std::nothrow) U8[anim_file_size]; + if (anim_data) { - anim_file_size = anim_file->getSize(); - anim_data = new(std::nothrow) U8[anim_file_size]; - if (anim_data) + LLFileSystem anim_file(mID, LLAssetType::AT_ANIMATION); + bool success = anim_file.read(anim_data, anim_file_size); + if (success) { - success = anim_file->read(anim_data, anim_file_size); /*Flawfinder: ignore*/ + LL_DEBUGS() << "Loading keyframe data for: " << getName() << ":" << getID() << " (" << anim_file_size << " bytes)" << LL_ENDL; + + LLDataPackerBinaryBuffer dp(anim_data, (S32)anim_file_size); + success = deserialize(dp, getID()); + if (!success) + { + LL_WARNS() << "Failed to decode asset for animation " << getName() << ":" << getID() << LL_ENDL; + } } else { - LL_WARNS() << "Failed to allocate buffer: " << anim_file_size << " " << mID << LL_ENDL; + LL_WARNS() << "Can't read animation file " << getID() << LL_ENDL; + } + delete []anim_data; + if (success) + { + mAssetStatus = ASSET_LOADED; + return STATUS_SUCCESS; } - delete anim_file; - anim_file = NULL; - } - - if (!success) - { - LL_WARNS() << "Can't open animation file " << mID << LL_ENDL; - mAssetStatus = ASSET_FETCH_FAILED; - return STATUS_FAILURE; } - - LL_DEBUGS() << "Loading keyframe data for: " << getName() << ":" << getID() << " (" << anim_file_size << " bytes)" << LL_ENDL; - - LLDataPackerBinaryBuffer dp(anim_data, anim_file_size); - - if (!deserialize(dp, getID())) + else { - LL_WARNS() << "Failed to decode asset for animation " << getName() << ":" << getID() << LL_ENDL; - mAssetStatus = ASSET_FETCH_FAILED; - return STATUS_FAILURE; + LL_WARNS() << "Failed to allocate buffer: " << anim_file_size << getID() << LL_ENDL; } - - delete []anim_data; - - mAssetStatus = ASSET_LOADED; - return STATUS_SUCCESS; + mAssetStatus = ASSET_FETCH_FAILED; + return STATUS_FAILURE; } //----------------------------------------------------------------------------- @@ -2175,7 +2163,7 @@ bool LLKeyframeMotion::serialize(LLDataPacker& dp) const //----------------------------------------------------------------------------- // getFileSize() //----------------------------------------------------------------------------- -U32 LLKeyframeMotion::getFileSize() +S32 LLKeyframeMotion::getFileSize() { // serialize into a dummy buffer to calculate required size LLDataPackerBinaryBuffer dp; @@ -2443,36 +2431,43 @@ void LLKeyframeMotion::onLoadComplete(const LLUUID& asset_uuid, // asset already loaded return; } - LLFileSystem file(asset_uuid, type, LLFileSystem::READ); - S32 size = file.getSize(); + // set assetStatus to failed, will be set to loaded if we succeed + motionp->mAssetStatus = ASSET_FETCH_FAILED; - U8* buffer = new(std::nothrow) U8[size]; - if (!buffer) + S64 size = LLFileSystem::getFileSize(asset_uuid, type); + if (size > 0) { - LLError::LLUserWarningMsg::showOutOfMemory(); - LL_ERRS() << "Bad memory allocation for buffer of size: " << size << LL_ENDL; - } - file.read((U8*)buffer, size); /*Flawfinder: ignore*/ + U8* buffer = new (std::nothrow) U8[size]; + if (!buffer) + { + LLError::LLUserWarningMsg::showOutOfMemory(); + LL_ERRS() << "Bad memory allocation for buffer of size: " << size << LL_ENDL; + } + LLFileSystem file(asset_uuid, type, LLFileSystem::READ); + file.read(buffer, size); - LL_DEBUGS("Animation") << "Loading keyframe data for: " << motionp->getName() << ":" << motionp->getID() << " (" << size << " bytes)" << LL_ENDL; + LL_DEBUGS("Animation") << "Loading keyframe data for: " << motionp->getName() << ":" << motionp->getID() << " (" << size + << " bytes)" << LL_ENDL; - LLDataPackerBinaryBuffer dp(buffer, size); - if (motionp->deserialize(dp, asset_uuid)) - { - motionp->mAssetStatus = ASSET_LOADED; + LLDataPackerBinaryBuffer dp(buffer, (S32)size); + if (motionp->deserialize(dp, asset_uuid)) + { + motionp->mAssetStatus = ASSET_LOADED; + } + else + { + LL_WARNS() << "Failed to decode asset for animation " << motionp->getName() << ":" << motionp->getID() << LL_ENDL; + } + delete[] buffer; } else { - LL_WARNS() << "Failed to decode asset for animation " << motionp->getName() << ":" << motionp->getID() << LL_ENDL; - motionp->mAssetStatus = ASSET_FETCH_FAILED; + LL_WARNS() << "Failed to load asset for animation " << motionp->getName() << ":" << motionp->getID() << LL_ENDL; } - - delete[] buffer; } else { LL_WARNS() << "Failed to load asset for animation " << motionp->getName() << ":" << motionp->getID() << LL_ENDL; - motionp->mAssetStatus = ASSET_FETCH_FAILED; } } else diff --git a/indra/llcharacter/llkeyframemotion.h b/indra/llcharacter/llkeyframemotion.h index d5b27c8102..0cda2b7d92 100644 --- a/indra/llcharacter/llkeyframemotion.h +++ b/indra/llcharacter/llkeyframemotion.h @@ -154,7 +154,7 @@ class LLKeyframeMotion : void* user_data, S32 status, LLExtStat ext_status); public: - U32 getFileSize(); + S32 getFileSize(); bool serialize(LLDataPacker& dp) const; bool deserialize(LLDataPacker& dp, const LLUUID& asset_id, bool allow_invalid_joints = true); bool isLoaded() { return mJointMotionList != NULL; } diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index 0ceb2eb03b..8e92dc0e86 100755 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -32,9 +32,7 @@ #include "llerror.h" #include "stringize.h" -#if LL_WINDOWS -#include -#else +#if !LL_WINDOWS #include #include #endif @@ -312,7 +310,7 @@ inline DWORD decode_access_mode(std::ios_base::openmode omode) return GENERIC_READ; case LLFile::out: return GENERIC_WRITE; - case static_cast(LLFile::in | LLFile::out): + case LLFile::inout: return GENERIC_READ | GENERIC_WRITE; } if (omode & LLFile::app) @@ -322,7 +320,7 @@ inline DWORD decode_access_mode(std::ios_base::openmode omode) return 0; } -inline DWORD decode_open_create_flags(std::ios_base::openmode omode) +inline DWORD decode_open_create_flags(LLFile::openmode_t omode) { if (omode & LLFile::noreplace) { @@ -344,7 +342,7 @@ inline DWORD decode_open_create_flags(std::ios_base::openmode omode) return OPEN_ALWAYS; // open if it exists, otherwise create it } -inline DWORD decode_share_mode(int omode) +inline DWORD decode_share_mode(LLFile::openmode_t omode) { if (omode & LLFile::exclusive) { @@ -357,14 +355,14 @@ inline DWORD decode_share_mode(int omode) return FILE_SHARE_READ | FILE_SHARE_WRITE; // allow read and write access to others } -inline DWORD decode_attributes(std::ios_base::openmode omode, int perm) +inline DWORD decode_attributes(LLFile::openmode_t omode, int perm) { return (perm & S_IWRITE) ? FILE_ATTRIBUTE_NORMAL : FILE_ATTRIBUTE_READONLY; } -// Under Windows the values for the std::ios_base::seekdir constants match the according FILE_BEGIN +// Under Windows the values for the LLFile::seekdir_t constants match the according FILE_BEGIN // and other constants but we do a programmatic translation for now to be sure -static DWORD seek_mode_from_dir(std::ios_base::seekdir seekdir) +static DWORD seek_mode_from_dir(LLFile::seekdir_t seekdir) { switch (seekdir) { @@ -401,7 +399,7 @@ inline int set_ec_to_outofmemory_error(std::error_code& ec) return set_ec_from_system_error(ec, ENOMEM); } -inline int decode_access_mode(std::ios_base::openmode omode) +inline int decode_access_mode(LLFile::openmode_t omode) { if (omode & LLFile::out) { @@ -412,18 +410,9 @@ inline int decode_access_mode(std::ios_base::openmode omode) return O_WRONLY; } return O_RDONLY; - - /*switch (omode & (LLFile::in | LLFile::out)) - { - case LLFile::out: - return O_WRONLY; - case static_cast(LLFile::in | LLFile::out): - return O_RDWR; - } - return O_RDONLY;*/ } -inline int decode_open_mode(std::ios_base::openmode omode) +inline int decode_open_mode(LLFile::openmode_t omode) { int flags = O_CREAT | decode_access_mode(omode); if (omode & LLFile::app) @@ -445,7 +434,7 @@ inline int decode_open_mode(std::ios_base::openmode omode) return flags; } -inline int decode_lock_mode(std::ios_base::openmode omode) +inline int decode_lock_mode(LLFile::openmode_t omode) { int lmode = omode & LLFile::noblock ? LOCK_NB : 0; if (omode & LLFile::lock_mask) @@ -459,9 +448,9 @@ inline int decode_lock_mode(std::ios_base::openmode omode) return lmode | LOCK_UN; } -// Under Linux and Mac the values for the std::ios_base::seekdir constants match the according SEEK_SET +// Under Linux and Mac the values for the LLFile::seekdir_t constants match the according SEEK_SET // and other constants but we do a programmatic translation for now to be sure -inline int seek_mode_from_dir(std::ios_base::seekdir seekdir) +inline int seek_mode_from_dir(LLFile::seekdir_t seekdir) { switch (seekdir) { @@ -483,10 +472,10 @@ inline int clear_error(std::error_code& ec) return 0; } -inline bool are_open_mode_flags_invalid(std::ios_base::openmode omode) +inline bool are_open_mode_flags_invalid(LLFile::openmode_t omode) { // at least one of input or output needs to be specified - if (!(omode & (LLFile::in | LLFile::out))) + if (!(omode & (LLFile::inout))) { return true; } @@ -506,7 +495,7 @@ inline bool are_open_mode_flags_invalid(std::ios_base::openmode omode) //---------------------------------------------------------------------------------------- // class member functions //---------------------------------------------------------------------------------------- -int LLFile::open(const std::string& filename, std::ios_base::openmode omode, std::error_code& ec, int perm) +int LLFile::open(const std::string& filename, LLFile::openmode_t omode, std::error_code& ec, int perm) { close(ec); if (are_open_mode_flags_invalid(omode)) @@ -593,14 +582,13 @@ int LLFile::seek(S64 pos, std::error_code& ec) return seek(pos, LLFile::beg, ec); } -int LLFile::seek(S64 offset, std::ios_base::seekdir dir, std::error_code& ec) +int LLFile::seek(S64 offset, LLFile::seekdir_t seekdir, std::error_code& ec) { S64 newOffset = 0; #if LL_WINDOWS - DWORD seekdir = seek_mode_from_dir(dir); LARGE_INTEGER value; value.QuadPart = offset; - if (SetFilePointerEx(mHandle, value, (PLARGE_INTEGER)&newOffset, seekdir)) + if (SetFilePointerEx(mHandle, value, (PLARGE_INTEGER)&newOffset, seek_mode_from_dir(seekdir))) #else newOffset = lseek(mHandle, offset, seek_mode_from_dir(dir)); if (newOffset != -1) @@ -919,8 +907,7 @@ S64 LLFile::read(const std::string& filename, void* buf, S64 offset, S64 nbytes, } else { - std::ios_base::openmode omode = LLFile::in | LLFile::binary; - + LLFile::openmode_t omode = LLFile::in | LLFile::binary; LLFile file(filename, omode, ec); if (!ec && (bool)file) { @@ -965,7 +952,7 @@ S64 LLFile::write(const std::string& filename, const void* buf, S64 offset, S64 } else { - std::ios_base::openmode omode = LLFile::out | LLFile::binary; + LLFile::openmode_t omode = LLFile::out | LLFile::binary; if (offset < 0) { omode |= LLFile::app; @@ -1129,17 +1116,18 @@ const std::string& LLFile::tmpdir() static std::string temppath; if (temppath.empty()) { - temppath = std::filesystem::temp_directory_path().string(); - } - #if LL_WINDOWS - char sep = '\\'; + char sep = '\\'; #else - char sep = '/'; + char sep = '/'; #endif - if (temppath[temppath.size() - 1] != sep) - { - temppath += sep; + // This function should probably rather be part of LLDir and actually is, although not as a static function + // LLDir::getTempDir() or LLDir::getExpandedFilename(LL_PATH_TEMP[[, subdir], filename]); + temppath = std::filesystem::temp_directory_path().string(); + if (!temppath.empty() && temppath[temppath.size() - 1] != sep) + { + temppath += sep; + } } return temppath; } diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h index dcd561ce7f..08f0555d91 100755 --- a/indra/llcommon/llfile.h +++ b/indra/llcommon/llfile.h @@ -41,7 +41,7 @@ #if LL_WINDOWS #include -// The Windows version of stat function and stat data structure are called _stat64 +// The Windows version of stat function and stat data structure are called _stat or _stat64 // We use _stat64 here to support 64-bit st_size and time_t values typedef struct _stat64 llstat; #else @@ -66,9 +66,10 @@ class LL_COMMON_API LLFile /// @name Constants /// ///@{ - /** These can be passed to the omode parameter of LLFile::open() and its constructor + /// These can be passed to the omode parameter of LLFile::open() and its constructor + typedef int openmode_t; - This is similar to the openmode flags for std:fstream but not exactly the same + /** This is similar to the openmode flags for std:fstream but not exactly the same std::fstream open() does not allow to open a file for writing without either forcing the file to be truncated on open or all write operations being always appended to the end of the file or failing to open when the file does not exist. @@ -102,13 +103,14 @@ class LL_COMMON_API LLFile + + + - + - " " ---------------------------------------------------------------------------------- */ - static const std::ios_base::openmode app = static_cast(1 << 1); // append to end - static const std::ios_base::openmode ate = static_cast(1 << 2); // initialize to end - static const std::ios_base::openmode binary = static_cast(1 << 3); // binary mode - static const std::ios_base::openmode in = static_cast(1 << 4); // for reading - static const std::ios_base::openmode out = static_cast(1 << 5); // for writing // for writing and reading - static const std::ios_base::openmode trunc = static_cast(1 << 6); // truncate on open - static const std::ios_base::openmode noreplace = static_cast(1 << 7); // no replace if it exists + static const openmode_t app = (1 << 1); // append to end + static const openmode_t ate = (1 << 2); // initialize to end + static const openmode_t binary = (1 << 3); // binary mode + static const openmode_t in = (1 << 4); // for reading + static const openmode_t out = (1 << 5); // for writing + static const openmode_t inout = in | out; // for writing and reading + static const openmode_t trunc = (1 << 6); // truncate on open + static const openmode_t noreplace = (1 << 7); // no replace if it exists /// Additional optional flags to omode in open() and lmode in fopen() or lock() /// to indicate which sort of lock if any to attempt to get @@ -123,20 +125,21 @@ class LL_COMMON_API LLFile /// therefore not be used to prevent random other applications from accessing the file, but it /// works for other viewer processes when they use either the LLFile::open() or LLFile::fopen() /// functions with the appropriate lock flags to open a file. - static const std::ios_base::openmode exclusive = static_cast(1 << 16); - static const std::ios_base::openmode shared = static_cast(1 << 17); + static const openmode_t exclusive = (1 << 16); // exclusive lock + static const openmode_t shared = (1 << 17); // shared lock, others may read /// Additional lmode flag to indicate to rather fail instead of blocking when trying /// to acquire a lock with LLFile::lock() - static const std::ios_base::openmode noblock = static_cast(1 << 18); + static const openmode_t noblock = (1 << 18); // don't wait when lock is not available /// The mask value for the lock mask bits - static const std::ios_base::openmode lock_mask = static_cast(exclusive | shared); + static const openmode_t lock_mask = (exclusive | shared); - /// One of these can be passed to the dir parameter of LLFile::seek() - static const std::ios_base::seekdir beg = std::ios_base::beg; - static const std::ios_base::seekdir cur = std::ios_base::cur; - static const std::ios_base::seekdir end = std::ios_base::end; + /// One of these can be passed to the seekdir parameter of LLFile::seek() + typedef std::ios_base::seekdir seekdir_t; + static const seekdir_t beg = std::ios_base::beg; + static const seekdir_t cur = std::ios_base::cur; + static const seekdir_t end = std::ios_base::end; ///@} // ================================================================================ @@ -157,7 +160,7 @@ class LL_COMMON_API LLFile } /// constructor opening the file - LLFile(const std::string& filename, std::ios_base::openmode omode, std::error_code& ec, int perm = 0666) : + LLFile(const std::string& filename, openmode_t omode, std::error_code& ec, int perm = 0666) : mHandle(InvalidHandle) { open(filename, omode, ec, perm); @@ -198,7 +201,7 @@ class LL_COMMON_API LLFile ///@{ /// Open a file with the specific open mode flags - int open(const std::string& filename, std::ios_base::openmode omode, std::error_code& ec, int perm = 0666); + int open(const std::string& filename, openmode_t omode, std::error_code& ec, int perm = 0666); ///< @returns 0 on success, -1 on failure /// Determine the size of the opened file @@ -213,8 +216,8 @@ class LL_COMMON_API LLFile int seek(S64 pos, std::error_code& ec); ///< @returns 0 on success, -1 on failure - /// Move the file pointer to the specified position relative to dir - int seek(S64 offset, std::ios_base::seekdir dir, std::error_code& ec); + /// Move the file pointer to the specified position relative to seekdir + int seek(S64 offset, LLFile::seekdir_t seekdir, std::error_code& ec); ///< @returns 0 on success, -1 on failure /// Read the specified number of bytes into the buffer starting at the current file pointer @@ -277,14 +280,14 @@ class LL_COMMON_API LLFile /// /// lmode is optional and allows to lock the file for other processes either as a shared lock or an /// exclusive lock. If the requested lock conflicts with an already existing lock, the open fails. - /// Pass either LLFIle::exclusive or LLFile::shared to this parameter if you want to prevent other + /// Pass either LLFile::exclusive or LLFile::shared to this parameter if you want to prevent other /// processes from reading (exclusive lock) or writing (shared lock) to the file. It will always use /// LLFile::noblock, meaning the open will immediately fail if it conflicts with an existing lock on the /// file. /// /// @returns a valid LLFILE* pointer on success that can be passed to the fread() and fwrite() functions /// and some other f functions in the Standard C library that accept a FILE* as parameter - /// or NULL on failure + /// or nullptr on failure /// Close a file handle opened with fopen() above static int close(LLFILE * file); @@ -411,10 +414,10 @@ class LL_COMMON_API LLFile private: #if LL_WINDOWS - typedef HANDLE llfile_handle_t; + typedef HANDLE llfile_handle_t; const llfile_handle_t InvalidHandle = INVALID_HANDLE_VALUE; #else - typedef int llfile_handle_t; + typedef int llfile_handle_t; const llfile_handle_t InvalidHandle = -1; #endif @@ -438,8 +441,8 @@ class LL_COMMON_API LLFile /// /// @returns the path as a std::wstring path #endif - llfile_handle_t mHandle; // The file handle/descriptor - std::ios_base::openmode mOpen; // Used to emulate std::ios_base::app under Windows + llfile_handle_t mHandle; // The file handle/descriptor + openmode_t mOpen; // Used to emulate std::ios_base::app under Windows }; #if LL_WINDOWS diff --git a/indra/llmessage/llassetstorage.cpp b/indra/llmessage/llassetstorage.cpp index 34eeacb273..99ad7468cd 100644 --- a/indra/llmessage/llassetstorage.cpp +++ b/indra/llmessage/llassetstorage.cpp @@ -450,25 +450,20 @@ bool LLAssetStorage::findInCacheAndInvokeCallback(const LLUUID& uuid, LLAssetTyp llassert(callback != NULL); } - bool exists = LLFileSystem::getExists(uuid, type); - if (exists) + LLFileSystem file(uuid, type); + S32 size = file.getSize(); + if (size > 0) { - LLFileSystem file(uuid, type); - U32 size = file.getSize(); - if (size > 0) - { - // we've already got the file - if (callback) - { - callback(uuid, type, user_data, LL_ERR_NOERR, LLExtStat::CACHE_CACHED); - } - return true; - } - else + // we've already got the file + if (callback) { - LL_WARNS("AssetStorage") << "Asset vfile " << uuid << ":" << type - << " found in static cache with bad size " << size << ", ignoring" << LL_ENDL; + callback(uuid, type, user_data, LL_ERR_NOERR, LLExtStat::CACHE_CACHED); } + return true; + } + else if (size == 0) + { + LL_WARNS("AssetStorage") << "Empty asset vfile " << uuid << ":" << type << " found in static cache, ignoring" << LL_ENDL; } return false; } @@ -525,10 +520,8 @@ void LLAssetStorage::getAssetData(const LLUUID uuid, return; } - bool exists = LLFileSystem::getExists(uuid, type); LLFileSystem file(uuid, type); - U32 size = exists ? file.getSize() : 0; - + S32 size = file.getSize(); if (size > 0) { LL_PROFILE_ZONE_NAMED("gad - file in cache"); @@ -544,9 +537,9 @@ void LLAssetStorage::getAssetData(const LLUUID uuid, } else { - if (exists) + if (!size) { - LL_WARNS("AssetStorage") << "Asset vfile " << uuid << ":" << type << " found with bad size " << file.getSize() << ", removing" << LL_ENDL; + LL_WARNS("AssetStorage") << "Empt asset vfile " << uuid << ":" << type << " found, removing" << LL_ENDL; file.remove(); } @@ -556,7 +549,7 @@ void LLAssetStorage::getAssetData(const LLUUID uuid, for (request_list_t::iterator iter = mPendingDownloads.begin(); iter != mPendingDownloads.end(); ++iter ) { - LLAssetRequest *tmp = *iter; + LLAssetRequest *tmp = *iter; if ((type == tmp->getType()) && (uuid == tmp->getUUID())) { if (callback == tmp->mDownCallback && user_data == tmp->mUserData) @@ -674,16 +667,14 @@ void LLAssetStorage::downloadCompleteCallback( { // we might have gotten a zero-size file LLFileSystem vfile(callback_id, callback_type); - if (vfile.getSize() <= 0) + bytes_fetched = vfile.getSize(); + if (bytes_fetched <= 0) { LL_WARNS("AssetStorage") << "downloadCompleteCallback has non-existent or zero-size asset " << callback_id << LL_ENDL; result = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE; vfile.remove(); - } - else - { - bytes_fetched = vfile.getSize(); + bytes_fetched = 0; } } @@ -723,10 +714,8 @@ void LLAssetStorage::getEstateAsset( return; } - bool exists = LLFileSystem::getExists(asset_id, atype); LLFileSystem file(asset_id, atype); - U32 size = exists ? file.getSize() : 0; - + S32 size = file.getSize(); if (size > 0) { // we've already got the file @@ -739,9 +728,9 @@ void LLAssetStorage::getEstateAsset( } else { - if (exists) + if (size == 0) { - LL_WARNS("AssetStorage") << "Asset vfile " << asset_id << ":" << atype << " found with bad size " << file.getSize() << ", removing" << LL_ENDL; + LL_WARNS("AssetStorage") << "Empty asset vfile " << asset_id << ":" << atype << " found, removing" << LL_ENDL; file.remove(); } @@ -849,22 +838,19 @@ void LLAssetStorage::getInvItemAsset( { LL_DEBUGS() << "LLAssetStorage::getInvItemAsset() - " << asset_id << "," << LLAssetType::lookup(atype) << LL_ENDL; - bool exists = false; - U32 size = 0; - - if(asset_id.notNull()) + S32 size = 0; + if (asset_id.notNull()) { if (findInCacheAndInvokeCallback( asset_id, atype, callback, user_data)) { return; } - exists = LLFileSystem::getExists(asset_id, atype); LLFileSystem file(asset_id, atype); - size = exists ? file.getSize() : 0; - if(exists && size < 1) + size = file.getSize(); + if (size == 0) { - LL_WARNS("AssetStorage") << "Asset vfile " << asset_id << ":" << atype << " found with bad size " << file.getSize() << ", removing" << LL_ENDL; + LL_WARNS("AssetStorage") << "Empty asset vfile " << asset_id << ":" << atype << " found, removing" << LL_ENDL; file.remove(); } diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp index b24e5e4fcc..e859fa83fb 100644 --- a/indra/llmessage/llcorehttputil.cpp +++ b/indra/llmessage/llcorehttputil.cpp @@ -781,12 +781,15 @@ LLSD HttpCoroutineAdapter::postFileAndSuspend(LLCore::HttpRequest::ptr_t request LLFileSystem vfile(assetId, assetType, LLFileSystem::READ); S32 fileSize = vfile.getSize(); - U8* fileBuffer; - fileBuffer = new U8[fileSize]; - vfile.read(fileBuffer, fileSize); + if (fileSize > 0) + { + U8* fileBuffer; + fileBuffer = new U8[fileSize]; + vfile.read(fileBuffer, fileSize); - outs.write((char*)fileBuffer, fileSize); - delete[] fileBuffer; + outs.write((char*)fileBuffer, fileSize); + delete[] fileBuffer; + } } return postAndSuspend(request, url, fileData, options, headers); diff --git a/indra/llmessage/lltransfersourceasset.cpp b/indra/llmessage/lltransfersourceasset.cpp index 082f12b8bf..2f2617c4a8 100644 --- a/indra/llmessage/lltransfersourceasset.cpp +++ b/indra/llmessage/lltransfersourceasset.cpp @@ -100,8 +100,8 @@ LLTSCode LLTransferSourceAsset::dataCallback(const S32 packet_id, } LLFileSystem vf(mParams.getAssetID(), mParams.getAssetType(), LLFileSystem::READ); - - if (!vf.getSize()) + S32 file_size = vf.getSize(); + if (file_size <= 0) { // Something bad happened with the asset request! return LLTS_ERROR; @@ -115,7 +115,7 @@ LLTSCode LLTransferSourceAsset::dataCallback(const S32 packet_id, // grab a buffer from the right place in the file if (!vf.seek(mCurPos, 0)) { - LL_WARNS() << "LLTransferSourceAsset Can't seek to " << mCurPos << " length " << vf.getSize() << LL_ENDL; + LL_WARNS() << "LLTransferSourceAsset Can't seek to " << mCurPos << " length " << file_size << LL_ENDL; LL_WARNS() << "While sending " << mParams.getAssetID() << LL_ENDL; return LLTS_ERROR; } @@ -123,11 +123,11 @@ LLTSCode LLTransferSourceAsset::dataCallback(const S32 packet_id, delete_returned = true; U8 *tmpp = new U8[max_bytes]; *data_handle = tmpp; - if (!vf.read(tmpp, max_bytes)) /* Flawfinder: Ignore */ + if (!vf.read(tmpp, max_bytes)) { // Read failure, need to deal with it. delete[] tmpp; - *data_handle = NULL; + *data_handle = nullptr; returned_bytes = 0; delete_returned = false; return LLTS_ERROR; @@ -136,13 +136,12 @@ LLTSCode LLTransferSourceAsset::dataCallback(const S32 packet_id, returned_bytes = vf.getLastBytesRead(); mCurPos += returned_bytes; - if (vf.eof()) { if (!returned_bytes) { delete[] tmpp; - *data_handle = NULL; + *data_handle = nullptr; returned_bytes = 0; delete_returned = false; } @@ -218,8 +217,6 @@ void LLTransferSourceAsset::responderCallback(const LLUUID& uuid, LLAssetType::E tsap->sendTransferStatus(status); } - - LLTransferSourceParamsAsset::LLTransferSourceParamsAsset() : LLTransferSourceParams(LLTST_ASSET), @@ -239,7 +236,6 @@ void LLTransferSourceParamsAsset::packParams(LLDataPacker &dp) const dp.packS32(mAssetType, "AssetType"); } - bool LLTransferSourceParamsAsset::unpackParams(LLDataPacker &dp) { S32 tmp_at; @@ -251,4 +247,3 @@ bool LLTransferSourceParamsAsset::unpackParams(LLDataPacker &dp) return true; } - diff --git a/indra/llmessage/llxfer_vfile.cpp b/indra/llmessage/llxfer_vfile.cpp index 4f31973f3d..5aae2f84a2 100644 --- a/indra/llmessage/llxfer_vfile.cpp +++ b/indra/llmessage/llxfer_vfile.cpp @@ -186,32 +186,21 @@ S32 LLXfer_VFile::startSend (U64 xfer_id, const LLHost &remote_host) mBufferStartOffset = 0; delete mVFile; - mVFile = NULL; - if(LLFileSystem::getExists(mLocalID, mType)) - { - mVFile = new LLFileSystem(mLocalID, mType, LLFileSystem::READ); - if (mVFile->getSize() <= 0) - { - LL_WARNS("Xfer") << "LLXfer_VFile::startSend() cache file " << mLocalID << "." << LLAssetType::lookup(mType) - << " has unexpected file size of " << mVFile->getSize() << LL_ENDL; - delete mVFile; - mVFile = NULL; + mVFile = new LLFileSystem(mLocalID, mType, LLFileSystem::READ); + S32 file_size = mVFile->getSize(); + if (file_size <= 0) + { + LL_WARNS("Xfer") << "LLXfer_VFile::startSend() cache file " << mLocalID << "." << LLAssetType::lookup(mType) + << " has unexpected file size of " << file_size << LL_ENDL; + delete mVFile; + mVFile = nullptr; - return LL_ERR_FILE_EMPTY; - } + return LL_ERR_FILE_EMPTY; } - if(mVFile) - { - setXferSize(mVFile->getSize()); - mStatus = e_LL_XFER_PENDING; - } - else - { - LL_WARNS("Xfer") << "LLXfer_VFile::startSend() can't read cache file " << mLocalID << "." << LLAssetType::lookup(mType) << LL_ENDL; - retval = LL_ERR_FILE_NOT_FOUND; - } + setXferSize(file_size); + mStatus = e_LL_XFER_PENDING; return (retval); } @@ -223,7 +212,7 @@ void LLXfer_VFile::closeFileHandle() if (mVFile) { delete mVFile; - mVFile = NULL; + mVFile = nullptr; } } @@ -280,14 +269,14 @@ S32 LLXfer_VFile::suck(S32 start_position) if (mVFile) { // grab a buffer from the right place in the file - if (! mVFile->seek(start_position, 0)) + if (!mVFile->seek(start_position, 0)) { LL_WARNS("Xfer") << "VFile Xfer Can't seek to position " << start_position << ", file length " << mVFile->getSize() << LL_ENDL; LL_WARNS("Xfer") << "While sending file " << mLocalID << LL_ENDL; return -1; } - if (mVFile->read((U8*)mBuffer, LL_MAX_XFER_FILE_BUFFER)) /* Flawfinder : ignore */ + if (mVFile->read((U8*)mBuffer, LL_MAX_XFER_FILE_BUFFER)) { mBufferLength = mVFile->getLastBytesRead(); mBufferStartOffset = start_position; diff --git a/indra/newview/gltf/accessor.cpp b/indra/newview/gltf/accessor.cpp index 900c1da170..973d44ad11 100644 --- a/indra/newview/gltf/accessor.cpp +++ b/indra/newview/gltf/accessor.cpp @@ -134,10 +134,10 @@ bool Buffer::prep(Asset& asset) if (mUri.size() == UUID_STR_SIZE && LLUUID::parseUUID(mUri, &id) && id.notNull()) { // loaded from an asset, fetch the buffer data from the asset store LLFileSystem file(id, LLAssetType::AT_GLTF_BIN, LLFileSystem::READ); - - if (mByteLength > file.getSize()) + S32 file_size = file.getSize(); + if (mByteLength > file_size) { - LL_WARNS("GLTF") << "Unexpected glbin size: " << id << " is " << file.getSize() << " bytes, expected " << mByteLength << LL_ENDL; + LL_WARNS("GLTF") << "Unexpected glbin size: " << id << " is " << file_size << " bytes, expected " << mByteLength << LL_ENDL; return false; } diff --git a/indra/newview/gltfscenemanager.cpp b/indra/newview/gltfscenemanager.cpp index ac452b38a0..6d1d32f3bc 100644 --- a/indra/newview/gltfscenemanager.cpp +++ b/indra/newview/gltfscenemanager.cpp @@ -439,32 +439,41 @@ void GLTFSceneManager::onGLTFLoadComplete(const LLUUID& id, LLAssetType::EType a LLFileSystem file(id, asset_type, LLFileSystem::READ); std::string data; S32 file_size = file.getSize(); - data.resize(file_size); - file.read((U8*)data.data(), file_size); + if (file_size > 0) + { + data.resize(file_size); + file.read((U8*)data.data(), file_size); - boost::json::value json = boost::json::parse(data); + boost::json::value json = boost::json::parse(data); - std::shared_ptr asset = std::make_shared(json); - obj->mGLTFAsset = asset; + std::shared_ptr asset = std::make_shared(json); + obj->mGLTFAsset = asset; - for (auto& buffer : asset->mBuffers) - { - // for now just assume the buffer is already in the asset cache - LLUUID buffer_id; - if (LLUUID::parseUUID(buffer.mUri, &buffer_id)) + for (auto& buffer : asset->mBuffers) { - asset->mPendingBuffers++; + // for now just assume the buffer is already in the asset cache + LLUUID buffer_id; + if (LLUUID::parseUUID(buffer.mUri, &buffer_id)) + { + asset->mPendingBuffers++; - gAssetStorage->getAssetData(buffer_id, LLAssetType::AT_GLTF_BIN, onGLTFBinLoadComplete, obj); - } - else - { - LL_WARNS("GLTF") << "Buffer URI is not a valid UUID: " << buffer.mUri << " for asset id: " << id << ". Marking as missing." << LL_ENDL; - obj->mIsGLTFAssetMissing = true; - obj->unref(); - return; + gAssetStorage->getAssetData(buffer_id, LLAssetType::AT_GLTF_BIN, onGLTFBinLoadComplete, obj); + } + else + { + LL_WARNS("GLTF") << "Buffer URI is not a valid UUID: " << buffer.mUri << " for asset id: " << id + << ". Marking as missing." << LL_ENDL; + obj->mIsGLTFAssetMissing = true; + obj->unref(); + } } } + else + { + LL_WARNS("GLTF") << "Missing or empty file for asset id: " << id << ". Marking as missing." << LL_ENDL; + obj->mIsGLTFAssetMissing = true; + obj->unref(); + } } } else diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp index 4cb6e7be96..5d9b9fa3d5 100644 --- a/indra/newview/llfloaterregioninfo.cpp +++ b/indra/newview/llfloaterregioninfo.cpp @@ -2750,36 +2750,37 @@ void LLPanelEstateCovenant::onLoadComplete(const LLUUID& asset_uuid, { LL_INFOS() << "LLPanelEstateCovenant::onLoadComplete()" << LL_ENDL; LLPanelEstateCovenant* panelp = (LLPanelEstateCovenant*)user_data; - if( panelp ) + if (panelp) { - if(0 == status) + if (0 == status) { LLFileSystem file(asset_uuid, type, LLFileSystem::READ); - S32 file_length = file.getSize(); - - std::vector buffer(file_length+1); - file.read((U8*)&buffer[0], file_length); - // put a EOS at the end - buffer[file_length] = 0; - - if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) ) + if (file_length > 0) { - if( !panelp->mEditor->importBuffer( &buffer[0], file_length+1 ) ) + std::vector buffer(file_length + 1); + file.read((U8*)&buffer[0], file_length); + // put a EOS at the end + buffer[file_length] = 0; + + if ((file_length > 19) && !strncmp(&buffer[0], "Linden text version", 19)) { - LL_WARNS() << "Problem importing estate covenant." << LL_ENDL; - LLNotificationsUtil::add("ProblemImportingEstateCovenant"); + if (!panelp->mEditor->importBuffer(&buffer[0], file_length + 1)) + { + LL_WARNS() << "Problem importing estate covenant." << LL_ENDL; + LLNotificationsUtil::add("ProblemImportingEstateCovenant"); + } + else + { + panelp->sendChangeCovenantID(asset_uuid); + } } else { + // Version 0 (just text, doesn't include version number) panelp->sendChangeCovenantID(asset_uuid); } } - else - { - // Version 0 (just text, doesn't include version number) - panelp->sendChangeCovenantID(asset_uuid); - } } else { diff --git a/indra/newview/llgesturemgr.cpp b/indra/newview/llgesturemgr.cpp index 550af7af53..4300377409 100644 --- a/indra/newview/llgesturemgr.cpp +++ b/indra/newview/llgesturemgr.cpp @@ -1119,115 +1119,120 @@ void LLGestureMgr::onLoadComplete(const LLUUID& asset_uuid, bool deactivate_similar = info->mDeactivateSimilar; delete info; - info = NULL; + info = nullptr; LLGestureMgr& self = LLGestureMgr::instance(); self.mLoadingCount--; if (0 == status) { + bool ok = false; LLFileSystem file(asset_uuid, type, LLFileSystem::READ); - S32 size = file.getSize(); + S32 file_size = file.getSize(); + if (file_size > 0) + { + std::vector buffer(file_size + 1); - std::vector buffer(size+1); + file.read((U8*)&buffer[0], file_size); + // ensure there's a trailing NULL so strlen will work. + buffer[file_size] = '\0'; - file.read((U8*)&buffer[0], size); - // ensure there's a trailing NULL so strlen will work. - buffer[size] = '\0'; + LLMultiGesture* gesture = new LLMultiGesture(); - LLMultiGesture* gesture = new LLMultiGesture(); + LLDataPackerAsciiBuffer dp(&buffer[0], file_size + 1); + ok = gesture->deserialize(dp); + if (ok) + { + if (deactivate_similar) + { + self.deactivateSimilarGestures(gesture, item_id); - LLDataPackerAsciiBuffer dp(&buffer[0], size+1); - bool ok = gesture->deserialize(dp); + // Display deactivation message if this was the last of the bunch. + if (self.mLoadingCount == 0 && self.mDeactivateSimilarNames.length() > 0) + { + // we're done with this set of deactivations + LLSD args; + args["NAMES"] = self.mDeactivateSimilarNames; + LLNotificationsUtil::add("DeactivatedGesturesTrigger", args); + } + } - if (ok) - { - if (deactivate_similar) - { - self.deactivateSimilarGestures(gesture, item_id); + LLViewerInventoryItem* item = gInventory.getItem(item_id); + if (item) + { + gesture->mName = item->getName(); + } + else + { + // Watch this item and set gesture name when item exists in inventory + self.setFetchID(item_id); + self.startFetch(); + } - // Display deactivation message if this was the last of the bunch. - if (self.mLoadingCount == 0 - && self.mDeactivateSimilarNames.length() > 0) + item_map_t::iterator it = self.mActive.find(item_id); + if (it == self.mActive.end()) { - // we're done with this set of deactivations - LLSD args; - args["NAMES"] = self.mDeactivateSimilarNames; - LLNotificationsUtil::add("DeactivatedGesturesTrigger", args); + // Gesture is supposed to be present, active, but NULL + LL_DEBUGS("GestureMgr") << "Gesture " << item_id << " not found in active list" << LL_ENDL; + } + else + { + LLMultiGesture* old_gesture = (*it).second; + if (old_gesture && old_gesture != gesture) + { + LL_DEBUGS("GestureMgr") << "Received dupplicate " << item_id << " callback" << LL_ENDL; + // In case somebody managest to activate, deactivate and + // then activate gesture again, before asset finishes loading. + // LLLoadInfo will have a different pointer, asset storage will + // see it as a different request, resulting in two callbacks. + + // deactivateSimilarGestures() did not turn this one off + // because of matching item_id + self.stopGesture(old_gesture); + + self.mActive.erase(item_id); + delete old_gesture; + old_gesture = nullptr; + } } - } - LLViewerInventoryItem* item = gInventory.getItem(item_id); - if(item) - { - gesture->mName = item->getName(); - } - else - { - // Watch this item and set gesture name when item exists in inventory - self.setFetchID(item_id); - self.startFetch(); - } + self.mActive[item_id] = gesture; - item_map_t::iterator it = self.mActive.find(item_id); - if (it == self.mActive.end()) - { - // Gesture is supposed to be present, active, but NULL - LL_DEBUGS("GestureMgr") << "Gesture " << item_id << " not found in active list" << LL_ENDL; - } - else - { - LLMultiGesture* old_gesture = (*it).second; - if (old_gesture && old_gesture != gesture) - { - LL_DEBUGS("GestureMgr") << "Received dupplicate " << item_id << " callback" << LL_ENDL; - // In case somebody managest to activate, deactivate and - // then activate gesture again, before asset finishes loading. - // LLLoadInfo will have a different pointer, asset storage will - // see it as a different request, resulting in two callbacks. - - // deactivateSimilarGestures() did not turn this one off - // because of matching item_id - self.stopGesture(old_gesture); + // Everything has been successful. Add to the active list. + gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id); - self.mActive.erase(item_id); - delete old_gesture; - old_gesture = NULL; + if (inform_server) + { + // Inform the database of this change + LLMessageSystem* msg = gMessageSystem; + msg->newMessage("ActivateGestures"); + msg->nextBlock("AgentData"); + msg->addUUID("AgentID", gAgent.getID()); + msg->addUUID("SessionID", gAgent.getSessionID()); + msg->addU32("Flags", 0x0); + + msg->nextBlock("Data"); + msg->addUUID("ItemID", item_id); + msg->addUUID("AssetID", asset_uuid); + msg->addU32("GestureFlags", 0x0); + + gAgent.sendReliableMessage(); } - } - - self.mActive[item_id] = gesture; + callback_map_t::iterator i_cb = self.mCallbackMap.find(item_id); - // Everything has been successful. Add to the active list. - gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id); + if (i_cb != self.mCallbackMap.end()) + { + i_cb->second(gesture); + self.mCallbackMap.erase(i_cb); + } - if (inform_server) - { - // Inform the database of this change - LLMessageSystem* msg = gMessageSystem; - msg->newMessage("ActivateGestures"); - msg->nextBlock("AgentData"); - msg->addUUID("AgentID", gAgent.getID()); - msg->addUUID("SessionID", gAgent.getSessionID()); - msg->addU32("Flags", 0x0); - - msg->nextBlock("Data"); - msg->addUUID("ItemID", item_id); - msg->addUUID("AssetID", asset_uuid); - msg->addU32("GestureFlags", 0x0); - - gAgent.sendReliableMessage(); + self.notifyObservers(); } - callback_map_t::iterator i_cb = self.mCallbackMap.find(item_id); - - if(i_cb != self.mCallbackMap.end()) + else { - i_cb->second(gesture); - self.mCallbackMap.erase(i_cb); + delete gesture; } - - self.notifyObservers(); } - else + if (!ok) { LL_WARNS("GestureMgr") << "Unable to load gesture" << LL_ENDL; @@ -1242,13 +1247,10 @@ void LLGestureMgr::onLoadComplete(const LLUUID& asset_uuid, self.stopGesture(old_gesture); delete old_gesture; - old_gesture = NULL; + old_gesture = nullptr; } self.mActive.erase(item_id); } - - delete gesture; - gesture = NULL; } } else diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index ac8477a615..a44ee37be7 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -543,8 +543,8 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp { LL_PROFILE_ZONE_NAMED("gltf read asset"); LLFileSystem file(id, asset_type, LLFileSystem::READ); - auto size = file.getSize(); - if (!size) + S32 size = file.getSize(); + if (size <= 0) { return false; } diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 4e14f416e9..6e4c40898f 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -3487,20 +3487,28 @@ void LLMaterialEditor::onLoadComplete(const LLUUID& asset_uuid, if (0 == status) { LLFileSystem file(asset_uuid, type, LLFileSystem::READ); - S32 file_length = file.getSize(); + if (file_length > 0) + { + std::vector buffer(file_length + 1); + file.read((U8*)&buffer[0], file_length); - std::vector buffer(file_length + 1); - file.read((U8*)&buffer[0], file_length); - - editor->decodeAsset(buffer); + editor->decodeAsset(buffer); - bool allow_modify = editor->canModify(editor->mObjectUUID, editor->getItem()); - bool source_library = editor->mObjectUUID.isNull() && gInventory.isObjectDescendentOf(editor->mItemUUID, gInventory.getLibraryRootFolderID()); - editor->setEnableEditing(allow_modify && !source_library); - editor->resetUnsavedChanges(); - editor->mAssetStatus = PREVIEW_ASSET_LOADED; - editor->setEnabled(true); // ready for use + bool allow_modify = editor->canModify(editor->mObjectUUID, editor->getItem()); + bool source_library = + editor->mObjectUUID.isNull() && gInventory.isObjectDescendentOf(editor->mItemUUID, gInventory.getLibraryRootFolderID()); + editor->setEnableEditing(allow_modify && !source_library); + editor->resetUnsavedChanges(); + editor->mAssetStatus = PREVIEW_ASSET_LOADED; + editor->setEnabled(true); // ready for use + } + else + { + LL_WARNS("MaterialEditor") << "Asset id file error: " << asset_uuid << LL_ENDL; + editor->mAssetStatus = PREVIEW_ASSET_ERROR; + editor->setEnabled(false); + } } else { diff --git a/indra/newview/llpreviewgesture.cpp b/indra/newview/llpreviewgesture.cpp index 66dcd2f7ba..91bea0bc63 100644 --- a/indra/newview/llpreviewgesture.cpp +++ b/indra/newview/llpreviewgesture.cpp @@ -852,40 +852,42 @@ void LLPreviewGesture::onLoadComplete(const LLUUID& asset_uuid, LLPreviewGesture* self = LLFloaterReg::findTypedInstance("preview_gesture", *item_idp); if (self) { + // set assetStatus to error, will be set to loaded if we were successful + self->mAssetStatus = PREVIEW_ASSET_ERROR; if (0 == status) { + bool ok = false; LLFileSystem file(asset_uuid, type, LLFileSystem::READ); S32 size = file.getSize(); + if (size > 0) + { + std::vector buffer(size + 1); + file.read((U8*)&buffer[0], size); + buffer[size] = '\0'; - std::vector buffer(size+1); - file.read((U8*)&buffer[0], size); - buffer[size] = '\0'; - - LLMultiGesture* gesture = new LLMultiGesture(); - - LLDataPackerAsciiBuffer dp(&buffer[0], size+1); - bool ok = gesture->deserialize(dp); + LLMultiGesture* gesture = new LLMultiGesture(); - if (ok) - { - // Everything has been successful. Load up the UI. - self->loadUIFromGesture(gesture); + LLDataPackerAsciiBuffer dp(&buffer[0], size + 1); + ok = gesture->deserialize(dp); + if (ok) + { + // Everything has been successful. Load up the UI. + self->loadUIFromGesture(gesture); - self->mStepList->selectFirstItem(); + self->mStepList->selectFirstItem(); - self->mDirty = false; - self->refresh(); - self->refreshFromItem(); // to update description and title + self->mDirty = false; + self->refresh(); + self->refreshFromItem(); // to update description and title + self->mAssetStatus = PREVIEW_ASSET_LOADED; + } + delete gesture; } - else + + if (!ok) { LL_WARNS() << "Unable to load gesture" << LL_ENDL; } - - delete gesture; - gesture = NULL; - - self->mAssetStatus = PREVIEW_ASSET_LOADED; } else { @@ -898,13 +900,10 @@ void LLPreviewGesture::onLoadComplete(const LLUUID& asset_uuid, { LLDelayedGestureError::gestureFailedToLoad( *item_idp ); } - LL_WARNS() << "Problem loading gesture: " << status << LL_ENDL; - self->mAssetStatus = PREVIEW_ASSET_ERROR; } } delete item_idp; - item_idp = NULL; } diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp index 4fe661b055..b6651f6c41 100755 --- a/indra/newview/llpreviewnotecard.cpp +++ b/indra/newview/llpreviewnotecard.cpp @@ -357,41 +357,44 @@ void LLPreviewNotecard::onLoadComplete(const LLUUID& asset_uuid, LL_INFOS() << "LLPreviewNotecard::onLoadComplete()" << LL_ENDL; LLSD* floater_key = (LLSD*)user_data; LLPreviewNotecard* preview = LLFloaterReg::findTypedInstance("preview_notecard", *floater_key); - if( preview ) + if (preview) { - if(0 == status) + // set assetStatus to error, will be set to loaded if we were successful + preview->mAssetStatus = PREVIEW_ASSET_ERROR; + if (0 == status) { LLFileSystem file(asset_uuid, type, LLFileSystem::READ); S32 file_length = file.getSize(); + if (file_length > 0) + { + std::vector buffer(file_length + 1); + file.read((U8*)&buffer[0], file_length); - std::vector buffer(file_length+1); - file.read((U8*)&buffer[0], file_length); - - // put a EOS at the end - buffer[file_length] = 0; - + // put a EOS at the end + buffer[file_length] = 0; - LLViewerTextEditor* previewEditor = preview->mEditor; + LLViewerTextEditor* previewEditor = preview->mEditor; - if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) ) - { - if( !previewEditor->importBuffer( &buffer[0], file_length+1 ) ) + if ((file_length > 19) && !strncmp(&buffer[0], "Linden text version", 19)) { - LL_WARNS() << "Problem importing notecard" << LL_ENDL; + if (!previewEditor->importBuffer(&buffer[0], file_length + 1)) + { + LL_WARNS() << "Problem importing notecard" << LL_ENDL; + } + } + else + { + // Version 0 (just text, doesn't include version number) + previewEditor->setText(LLStringExplicit(&buffer[0])); } - } - else - { - // Version 0 (just text, doesn't include version number) - previewEditor->setText(LLStringExplicit(&buffer[0])); - } - previewEditor->makePristine(); - bool modifiable = preview->canModify(preview->mObjectID, preview->getItem()); - preview->setEnabled(modifiable); - preview->syncExternal(); - preview->mAssetStatus = PREVIEW_ASSET_LOADED; + previewEditor->makePristine(); + bool modifiable = preview->canModify(preview->mObjectID, preview->getItem()); + preview->setEnabled(modifiable); + preview->syncExternal(); + preview->mAssetStatus = PREVIEW_ASSET_LOADED; + } } else { @@ -408,9 +411,7 @@ void LLPreviewNotecard::onLoadComplete(const LLUUID& asset_uuid, { LLNotificationsUtil::add("UnableToLoadNotecard"); } - LL_WARNS() << "Problem loading notecard: " << status << LL_ENDL; - preview->mAssetStatus = PREVIEW_ASSET_ERROR; } } delete floater_key; diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 2c436198e3..af3d2947e3 100755 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -1862,39 +1862,43 @@ void LLPreviewLSL::onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType t << LL_ENDL; LLUUID* item_uuid = (LLUUID*)user_data; LLPreviewLSL* preview = LLFloaterReg::findTypedInstance("preview_script", *item_uuid); - if( preview ) + if (preview) { - if(0 == status) + // set assetStatus to error, will be reset to loaded if we were successful + preview->mAssetStatus = PREVIEW_ASSET_ERROR; + if (0 == status) { LLFileSystem file(asset_uuid, type); S32 file_length = file.getSize(); - - std::vector buffer(file_length+1); - file.read((U8*)&buffer[0], file_length); - - // put a EOS at the end - buffer[file_length] = 0; - preview->mScriptEd->setScriptText(LLStringExplicit(&buffer[0]), true); - preview->mScriptEd->mEditor->makePristine(); - - std::string script_name = DEFAULT_SCRIPT_NAME; - LLInventoryItem* item = gInventory.getItem(*item_uuid); - bool is_modifiable = false; - if (item) + if (file_length > 0) { - if (!item->getName().empty()) + std::vector buffer(file_length + 1); + file.read((U8*)&buffer[0], file_length); + + // put a EOS at the end + buffer[file_length] = 0; + preview->mScriptEd->setScriptText(LLStringExplicit(&buffer[0]), true); + preview->mScriptEd->mEditor->makePristine(); + + std::string script_name = DEFAULT_SCRIPT_NAME; + LLInventoryItem* item = gInventory.getItem(*item_uuid); + bool is_modifiable = false; + if (item) { - script_name = item->getName(); - } - if (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE)) - { - is_modifiable = true; + if (!item->getName().empty()) + { + script_name = item->getName(); + } + if (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE)) + { + is_modifiable = true; + } } + preview->mScriptEd->setScriptName(script_name); + preview->mScriptEd->setEnableEditing(is_modifiable); + preview->mScriptEd->setAssetID(asset_uuid); + preview->mAssetStatus = PREVIEW_ASSET_LOADED; } - preview->mScriptEd->setScriptName(script_name); - preview->mScriptEd->setEnableEditing(is_modifiable); - preview->mScriptEd->setAssetID(asset_uuid); - preview->mAssetStatus = PREVIEW_ASSET_LOADED; } else { @@ -1911,8 +1915,6 @@ void LLPreviewLSL::onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType t { LLNotificationsUtil::add("UnableToLoadScript"); } - - preview->mAssetStatus = PREVIEW_ASSET_ERROR; LL_WARNS() << "Problem loading script: " << status << LL_ENDL; } } @@ -2177,24 +2179,29 @@ void LLLiveLSLEditor::loadScriptText(const LLUUID &uuid, LLAssetType::EType type { LLFileSystem file(uuid, type); S32 file_length = file.getSize(); - std::vector buffer(file_length + 1); - file.read((U8*)&buffer[0], file_length); - - if (file.getLastBytesRead() != file_length || - file_length <= 0) + if (file_length > 0) { - LL_WARNS() << "Error reading " << uuid << ":" << type << LL_ENDL; - } + std::vector buffer(file_length + 1); + file.read((U8*)&buffer[0], file_length); - buffer[file_length] = '\0'; + if (file.getLastBytesRead() != file_length || file_length <= 0) + { + LL_WARNS() << "Error reading " << uuid << ":" << type << LL_ENDL; + } + buffer[file_length] = '\0'; - mScriptEd->setScriptText(LLStringExplicit(&buffer[0]), true); + mScriptEd->setScriptText(LLStringExplicit(&buffer[0]), true); + } + else + { + mScriptEd->setScriptText("", false); + } mScriptEd->makeEditorPristine(); std::string script_name = DEFAULT_SCRIPT_NAME; const LLInventoryItem* inv_item = getItem(); - if(inv_item) + if (inv_item) { script_name = inv_item->getName(); } diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp index 8329ed86da..c069f694f2 100644 --- a/indra/newview/llsettingsvo.cpp +++ b/indra/newview/llsettingsvo.cpp @@ -325,18 +325,19 @@ void LLSettingsVOBase::onAssetDownloadComplete(const LLUUID &asset_id, S32 statu { LLFileSystem file(asset_id, LLAssetType::AT_SETTINGS, LLFileSystem::READ); S32 size = file.getSize(); + if (size > 0) + { + std::string buffer(size + 1, '\0'); + file.read((U8*)buffer.data(), size); - std::string buffer(size + 1, '\0'); - file.read((U8 *)buffer.data(), size); - - std::stringstream llsdstream(buffer); - LLSD llsdsettings; + std::stringstream llsdstream(buffer); + LLSD llsdsettings; - if (LLSDSerialize::deserialize(llsdsettings, llsdstream, LLSDSerialize::SIZE_UNLIMITED)) - { - settings = createFromLLSD(llsdsettings); + if (LLSDSerialize::deserialize(llsdsettings, llsdstream, LLSDSerialize::SIZE_UNLIMITED)) + { + settings = createFromLLSD(llsdsettings); + } } - if (!settings) { status = 1; diff --git a/indra/newview/llviewerassetstorage.cpp b/indra/newview/llviewerassetstorage.cpp index e76d340eda..3d4b5c1e90 100644 --- a/indra/newview/llviewerassetstorage.cpp +++ b/indra/newview/llviewerassetstorage.cpp @@ -154,55 +154,38 @@ void LLViewerAssetStorage::storeAssetData( if (mUpstreamHost.isOk()) { - if (LLFileSystem::getExists(asset_id, asset_type)) + LLFileSystem vfile(asset_id, asset_type, LLFileSystem::READ); + S32 asset_size = vfile.getSize(); + if (asset_size > 0) { // Pack data into this packet if we can fit it. U8 buffer[MTUBYTES]; buffer[0] = 0; - LLFileSystem vfile(asset_id, asset_type, LLFileSystem::READ); - S32 asset_size = vfile.getSize(); - LLAssetRequest *req = new LLAssetRequest(asset_id, asset_type); req->mUpCallback = callback; req->mUserData = user_data; - if (asset_size < 1) - { - // This can happen if there's a bug in our code or if the cache has been corrupted. - LL_WARNS("AssetStorage") << "LLViewerAssetStorage::storeAssetData() Data _should_ already be in the cache, but it's not! " << asset_id << LL_ENDL; + // LLAssetStorage metric: Successful Request + const char *message = "Added to upload queue"; + reportMetric(asset_id, asset_type, LLStringUtil::null, LLUUID::null, asset_size, MR_OKAY, __FILE__, __LINE__, message ); - delete req; - if (callback) - { - callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_FAILED, LLExtStat::CACHE_CORRUPT); - } - return; + if (is_priority) + { + mPendingUploads.push_front(req); } else { - // LLAssetStorage metric: Successful Request - S32 size = (S32)LLFileSystem::getFileSize(asset_id, asset_type); - const char *message = "Added to upload queue"; - reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, size, MR_OKAY, __FILE__, __LINE__, message ); - - if(is_priority) - { - mPendingUploads.push_front(req); - } - else - { - mPendingUploads.push_back(req); - } + mPendingUploads.push_back(req); } // Read the data from the cache if it'll fit in this packet. if (asset_size + 100 < MTUBYTES) { - bool res = vfile.read(buffer, asset_size); /* Flawfinder: ignore */ + bool res = vfile.read(buffer, asset_size); S32 bytes_read = res ? vfile.getLastBytesRead() : 0; - if( bytes_read == asset_size ) + if (bytes_read == asset_size) { req->mDataSentInFirstPacket = true; //LL_INFOS() << "LLViewerAssetStorage::createAsset sending data in first packet" << LL_ENDL; @@ -233,7 +216,7 @@ void LLViewerAssetStorage::storeAssetData( mMessageSys->addBinaryDataFast( _PREHASH_AssetData, buffer, asset_size ); mMessageSys->sendReliable(mUpstreamHost); } - else + else if (asset_size < 0) { LL_WARNS("AssetStorage") << "AssetStorage: attempt to upload non-existent vfile " << asset_id << ":" << LLAssetType::lookup(asset_type) << LL_ENDL; reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_ZERO_SIZE, __FILE__, __LINE__, "The file didn't exist or was zero length (cache - can't tell which)" ); @@ -242,6 +225,15 @@ void LLViewerAssetStorage::storeAssetData( callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_NONEXISTENT_FILE, LLExtStat::NONEXISTENT_FILE); } } + else + { + // This can happen if there's a bug in our code or if the cache has been corrupted. + LL_WARNS("AssetStorage") << "LLViewerAssetStorage::storeAssetData() Data _should_ already be in the cache, but it's not! " << asset_id << LL_ENDL; + if (callback) + { + callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_FAILED, LLExtStat::CACHE_CORRUPT); + } + } } else { diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index 3a7b721f70..79220646ad 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -6835,33 +6835,38 @@ void onCovenantLoadComplete(const LLUUID& asset_uuid, if (0 == status) { LLFileSystem file(asset_uuid, type, LLFileSystem::READ); - S32 file_length = file.getSize(); - - std::vector buffer(file_length+1); - file.read((U8*)&buffer[0], file_length); - // put a EOS at the end - buffer[file_length] = '\0'; - - if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) ) + if (file_length > 0) { - LLViewerTextEditor::Params params; - params.name("temp"); - params.max_text_length(file_length+1); - LLViewerTextEditor * editor = LLUICtrlFactory::create (params); - if( !editor->importBuffer( &buffer[0], file_length+1 ) ) + std::vector buffer(file_length + 1); + file.read((U8*)&buffer[0], file_length); + // put a EOS at the end + buffer[file_length] = '\0'; + + if ((file_length > 19) && !strncmp(&buffer[0], "Linden text version", 19)) { - LL_WARNS("Messaging") << "Problem importing estate covenant." << LL_ENDL; - covenant_text = "Problem importing estate covenant."; - delete editor; + LLViewerTextEditor::Params params; + params.name("temp"); + params.max_text_length(file_length + 1); + LLViewerTextEditor* editor = LLUICtrlFactory::create(params); + if (!editor->importBuffer(&buffer[0], file_length + 1)) + { + LL_WARNS("Messaging") << "Problem importing estate covenant." << LL_ENDL; + covenant_text = "Problem importing estate covenant."; + delete editor; + } + else + { + // Version 0 (just text, doesn't include version number) + editorp.reset(editor); // Use covenant from editorp; + } } else { - // Version 0 (just text, doesn't include version number) - editorp.reset(editor); // Use covenant from editorp; + file_length = 0; } } - else + if (file_length <= 0) { LL_WARNS("Messaging") << "Problem importing estate covenant: Covenant file format error." << LL_ENDL; covenant_text = "Problem importing estate covenant: Covenant file format error.";