Potential read beyond bounds in ReadCompressedIndexDataValuesFromBlob()
The function ReadCompressedIndexDataValuesFromBlob() checks buffer bounds using pointer arithmetic that can overflow, leading to a false negative. An attacker could supply a crafted blob that causes the function to read beyond the intended buffer, potentially leading to information disclosure or a crash.
- Fixed in 17 days
- Paid in 23 days
- Disclosed after 17 days
If the data blobs it uses are untrusted or defective, ReadCompressedIndexDataValuesFromBlob() could read beyond bounds.
The bugs are that its tests for buffer bounds can overflow, causing address-wrap and thus a false negative. This can occur on any platform that places user-mode data in the highest 0x7ffffff5 bytes [1] of the address space. (Thus, it could occur on, e.g., 32-bit Windows with the /3GB option).
The bugs are on lines 878 and 896, below:
844: nsresult
845: ReadCompressedIndexDataValuesFromBlob(const uint8_t* aBlobData,
846: uint32_t aBlobDataLength,
847: nsTArray<IndexDataValue>& aIndexValues)
848: {
...
859: const uint8_t* blobDataIter = aBlobData;
860: const uint8_t* blobDataEnd = aBlobData + aBlobDataLength;
861:
862: while (blobDataIter < blobDataEnd) {
863: int64_t indexId;
864: bool unique;
865: ReadCompressedIndexId(&blobDataIter, blobDataEnd, &indexId, &unique);
866:
867: if (NS_WARN_IF(blobDataIter == blobDataEnd)) {
868: IDB_REPORT_INTERNAL_ERR();
869: return NS_ERROR_FILE_CORRUPTED;
870: }
871:
872: // Read key buffer length.
873: const uint64_t keyBufferLength =
874: ReadCompressedNumber(&blobDataIter, blobDataEnd);
875:
876: if (NS_WARN_IF(blobDataIter == blobDataEnd) ||
877: NS_WARN_IF(keyBufferLength > uint64_t(UINT32_MAX)) ||
878: NS_WARN_IF(blobDataIter + keyBufferLength > blobDataEnd)) {
879: IDB_REPORT_INTERNAL_ERR();
880: return NS_ERROR_FILE_CORRUPTED;
881: }
882:
883: nsCString keyBuffer(reinterpret_cast<const char*>(blobDataIter),
884: uint32_t(keyBufferLength));
885: blobDataIter += keyBufferLength;
886:
887: IndexDataValue idv(indexId, unique, Key(keyBuffer));
888:
889: // Read sort key buffer length.
890: const uint64_t sortKeyBufferLength =
891: ReadCompressedNumber(&blobDataIter, blobDataEnd);
892:
893: if (sortKeyBufferLength > 0) {
894: if (NS_WARN_IF(blobDataIter == blobDataEnd) ||
895: NS_WARN_IF(sortKeyBufferLength > uint64_t(UINT32_MAX)) ||
896: NS_WARN_IF(blobDataIter + sortKeyBufferLength > blobDataEnd)) {
897: IDB_REPORT_INTERNAL_ERR();
898: return NS_ERROR_FILE_CORRUPTED;
899: }
900:
901: nsCString sortKeyBuffer(reinterpret_cast<const char*>(blobDataIter),
902: uint32_t(sortKeyBufferLength));
903: blobDataIter += sortKeyBufferLength;
904:
905: idv.mSortKey = Key(sortKeyBuffer);
906: }
If, e.g., |blobDataIter| == 0xbffff000, |aBlobDataLength| == 0x1000, and |keyBufferLength| = 0x41000000, then line 878's LHS would overflow to 0x00fff000, which would be <= |blobDataEnd| (0xc0000000), so the test incorrectly would conclude that everything was within bounds, allowing lines 883-84 to form a string from data read far beyond bounds.
[1] Derived from the maximum length of an nsCString.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the bounds check uses pointer addition that can overflow, so a large length value wraps around and passes the check.
Impact
An attacker could cause the function to read beyond the buffer, potentially leading to information disclosure or a crash, but only on platforms where user-mode data is placed in the highest part of the address space.
What the attacker needed
Untrusted or defective data blobs; platform with user-mode data in high address space
The fix
The bounds check should be rewritten to avoid pointer overflow, for example by comparing lengths instead of adding to the pointer.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a bug in a function that reads data from a blob. The function tries to check that it doesn't read past the end of the blob, but the check itself can be fooled by a very large number, causing it to read memory it shouldn't. This could let an attacker see data they shouldn't or crash the program.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.