Commit 450258ca authored by Joshua Pawlicki's avatar Joshua Pawlicki Committed by Commit Bot

Expand CRX magic number list in sniffer for CRX3


Bug: 831284
Change-Id: I84d27cfb61725524d1ec9b12ffaa1bda221529ff
Reviewed-on: https://chromium-review.googlesource.com/1005797Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Joshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549887}
parent 30b94a8a
...@@ -687,8 +687,8 @@ static bool SniffCRX(const char* content, ...@@ -687,8 +687,8 @@ static bool SniffCRX(const char* content,
// sniffing gives us less room for error. If the version number ever changes, // sniffing gives us less room for error. If the version number ever changes,
// we can just add an entry to this list. // we can just add an entry to this list.
static const struct MagicNumber kCRXMagicNumbers[] = { static const struct MagicNumber kCRXMagicNumbers[] = {
MAGIC_NUMBER("application/x-chrome-extension", "Cr24\x02\x00\x00\x00") MAGIC_NUMBER("application/x-chrome-extension", "Cr24\x02\x00\x00\x00"),
}; MAGIC_NUMBER("application/x-chrome-extension", "Cr24\x03\x00\x00\x00")};
// Only consider files that have the extension ".crx". // Only consider files that have the extension ".crx".
if (!base::EndsWith(url.path_piece(), ".crx", base::CompareCase::SENSITIVE)) if (!base::EndsWith(url.path_piece(), ".crx", base::CompareCase::SENSITIVE))
......
...@@ -95,66 +95,55 @@ TEST(MimeSnifferTest, BasicSniffingTest) { ...@@ -95,66 +95,55 @@ TEST(MimeSnifferTest, BasicSniffingTest) {
TEST(MimeSnifferTest, ChromeExtensionsTest) { TEST(MimeSnifferTest, ChromeExtensionsTest) {
SnifferTest tests[] = { SnifferTest tests[] = {
// schemes // schemes
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"http://www.example.com/foo.crx", "http://www.example.com/foo.crx", "", "application/x-chrome-extension"},
"", "application/x-chrome-extension" }, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, "https://www.example.com/foo.crx", "", "application/x-chrome-extension"},
"https://www.example.com/foo.crx", {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"", "application/x-chrome-extension" }, "ftp://www.example.com/foo.crx", "", "application/x-chrome-extension"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
"ftp://www.example.com/foo.crx", // some other mimetypes that should get converted
"", "application/x-chrome-extension" }, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"http://www.example.com/foo.crx", "text/plain",
// some other mimetypes that should get converted "application/x-chrome-extension"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"http://www.example.com/foo.crx", "http://www.example.com/foo.crx", "application/octet-stream",
"text/plain", "application/x-chrome-extension" }, "application/x-chrome-extension"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
"http://www.example.com/foo.crx", // success edge cases
"application/octet-stream", "application/x-chrome-extension" }, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"http://www.example.com/foo.crx?query=string", "",
// success edge cases "application/x-chrome-extension"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"http://www.example.com/foo.crx?query=string", "http://www.example.com/foo..crx", "", "application/x-chrome-extension"},
"", "application/x-chrome-extension" }, {"Cr24\x03\x00\x00\x00", sizeof("Cr24\x03\x00\x00\x00") - 1,
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, "http://www.example.com/foo..crx", "", "application/x-chrome-extension"},
"http://www.example.com/foo..crx",
"", "application/x-chrome-extension" }, // wrong file extension
{"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
// wrong file extension "http://www.example.com/foo.bin", "", "application/octet-stream"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"http://www.example.com/foo.bin", "http://www.example.com/foo.bin?monkey", "", "application/octet-stream"},
"", "application/octet-stream" }, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, "invalid-url", "", "application/octet-stream"},
"http://www.example.com/foo.bin?monkey", {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"", "application/octet-stream" }, "http://www.example.com", "", "application/octet-stream"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"invalid-url", "http://www.example.com/", "", "application/octet-stream"},
"", "application/octet-stream" }, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, "http://www.example.com/foo", "", "application/octet-stream"},
"http://www.example.com", {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"", "application/octet-stream" }, "http://www.example.com/foocrx", "", "application/octet-stream"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
"http://www.example.com/", "http://www.example.com/foo.crx.blech", "", "application/octet-stream"},
"", "application/octet-stream" },
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, // wrong magic
"http://www.example.com/foo", {"Cr24\x02\x00\x00\x01", sizeof("Cr24\x02\x00\x00\x01") - 1,
"", "application/octet-stream" }, "http://www.example.com/foo.crx?monkey", "", "application/octet-stream"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, {"PADDING_Cr24\x02\x00\x00\x00",
"http://www.example.com/foocrx", sizeof("PADDING_Cr24\x02\x00\x00\x00") - 1,
"", "application/octet-stream" }, "http://www.example.com/foo.crx?monkey", "", "application/octet-stream"},
{ "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
"http://www.example.com/foo.crx.blech",
"", "application/octet-stream" },
// wrong magic
{ "Cr24\x02\x00\x00\x01", sizeof("Cr24\x02\x00\x00\x01")-1,
"http://www.example.com/foo.crx?monkey",
"", "application/octet-stream" },
{ "PADDING_Cr24\x02\x00\x00\x00", sizeof("PADDING_Cr24\x02\x00\x00\x00")-1,
"http://www.example.com/foo.crx?monkey",
"", "application/octet-stream" },
}; };
TestArray(tests, arraysize(tests)); TestArray(tests, arraysize(tests));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment