Skip to content

Commit

Permalink
Bug 1656927 - Assertion failure: aContentType.Equals("image/avif"), a…
Browse files Browse the repository at this point in the history
…t /builds/worker/checkouts/gecko/image/imgLoader.cpp:2785. r=aosmond

Differential Revision: https://phabricator.services.mozilla.com/D85803
  • Loading branch information
baumanj committed Aug 4, 2020
1 parent 3948e90 commit 56c3c9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions image/imgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2729,6 +2729,8 @@ imgLoader::GetMIMETypeFromContent(nsIRequest* aRequest,
nsresult imgLoader::GetMimeTypeFromContent(const char* aContents,
uint32_t aLength,
nsACString& aContentType) {
nsAutoCString detected;

/* Is it a GIF? */
if (aLength >= 6 &&
(!strncmp(aContents, "GIF87a", 6) || !strncmp(aContents, "GIF89a", 6))) {
Expand Down Expand Up @@ -2781,8 +2783,9 @@ nsresult imgLoader::GetMimeTypeFromContent(const char* aContents,
aContentType.AssignLiteral(IMAGE_WEBP);

} else if (MatchesMP4(reinterpret_cast<const uint8_t*>(aContents), aLength,
aContentType)) {
MOZ_ASSERT(aContentType.Equals(IMAGE_AVIF));
detected) &&
detected.Equals(IMAGE_AVIF)) {
aContentType.AssignLiteral(IMAGE_AVIF);
} else {
/* none of the above? I give up */
return NS_ERROR_NOT_AVAILABLE;
Expand Down
10 changes: 10 additions & 0 deletions image/test/gtest/TestLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ TEST_F(ImageLoader, DetectAVIFCompatibleBrand) {
CheckMimeType(buffer, sizeof(buffer), IMAGE_AVIF);
}

TEST_F(ImageLoader, DetectNonImageMP4) {
const char buffer[] =
"\x00\x00\x00\x1c" // box length
"ftyp" // box type
"isom" // major brand
"\x00\x00\x02\x00" // minor version
"isomiso2mp41"; // compatible brands
CheckMimeType(buffer, sizeof(buffer), nullptr);
}

TEST_F(ImageLoader, DetectNone) {
const char buffer[] = "abcdefghijklmnop";
CheckMimeType(buffer, sizeof(buffer), nullptr);
Expand Down

0 comments on commit 56c3c9e

Please sign in to comment.