diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 84e32fabae0e..9aa5b3ffc1c2 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -2697,14 +2697,28 @@ Result GetTemporaryStorageLimit(nsIFile& aStorageDir) { 1024; } - // Check for disk capacity of user's device on which storage directory lives. - QM_TRY_INSPECT(const int64_t& diskCapacity, - MOZ_TO_RESULT_INVOKE_MEMBER(aStorageDir, GetDiskCapacity)); + constexpr int64_t teraByte = (1024LL * 1024LL * 1024LL * 1024LL); + constexpr int64_t maxAllowedCapacity = 8LL * teraByte; - MOZ_ASSERT(diskCapacity >= 0); + // Check for disk capacity of user's device on which storage directory lives. + int64_t diskCapacity = maxAllowedCapacity; + + // Log error when default disk capacity is returned due to the error + QM_WARNONLY_TRY(MOZ_TO_RESULT(aStorageDir.GetDiskCapacity(&diskCapacity))); + + MOZ_ASSERT(diskCapacity >= 0LL); // Allow temporary storage to consume up to 50% of disk capacity. - return diskCapacity / 2u; + int64_t capacityLimit = diskCapacity / 2LL; + + // If the disk capacity reported by the operating system is very + // large and potentially incorrect due to hardware issues, + // a hardcoded limit is supplied instead. + QM_WARNONLY_TRY( + OkIf(capacityLimit < maxAllowedCapacity), + ([&capacityLimit](const auto&) { capacityLimit = maxAllowedCapacity; })); + + return capacityLimit; } bool IsOriginUnaccessed(const FullOriginMetadata& aFullOriginMetadata, diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index 321f3a1ff9e7..e88565d5659f 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -1492,14 +1492,11 @@ nsresult nsLocalFile::GetDiskInfo(StatInfoFunc&& aStatInfoFunc, checkedResult = std::forward(aStatInfoFunc)(fs_buf); if (!checkedResult.isValid()) { - return NS_ERROR_FAILURE; + return NS_ERROR_CANNOT_CONVERT_DATA; } - *aResult = checkedResult.value(); - -# ifdef DEBUG_DISK_SPACE - printf("DiskInfo: %lu bytes\n", *aResult); -# endif + // If we return an error, *aValue will not be modified. + int64_t tentativeResult = checkedResult.value(); # if defined(USE_LINUX_QUOTACTL) @@ -1523,15 +1520,21 @@ nsresult nsLocalFile::GetDiskInfo(StatInfoFunc&& aStatInfoFunc, && dq.dqb_bhardlimit) { checkedResult = std::forward(aQuotaInfoFunc)(dq); if (!checkedResult.isValid()) { - return NS_ERROR_FAILURE; + return NS_ERROR_CANNOT_CONVERT_DATA; } - if (checkedResult.value() < *aResult) { - *aResult = checkedResult.value(); + if (checkedResult.value() < tentativeResult) { + tentativeResult = checkedResult.value(); } } # endif +# ifdef DEBUG_DISK_SPACE + printf("DiskInfo: %lu bytes\n", tentativeResult); +# endif + + *aResult = tentativeResult; + return NS_OK; #else diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index 4022af8dc1d0..37278f264d6f 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -2734,8 +2734,6 @@ nsLocalFile::GetDiskCapacity(int64_t* aDiskCapacity) { return NS_ERROR_INVALID_ARG; } - *aDiskCapacity = 0; - nsresult rv = ResolveAndStat(); if (NS_FAILED(rv)) { return rv;