Skip to content

Commit

Permalink
A path containing
Browse files Browse the repository at this point in the history
a .. component, eh?
Valid link target
  • Loading branch information
John-LittleBearLabs committed Jan 30, 2024
1 parent ae4cc31 commit 41fddd8
Show file tree
Hide file tree
Showing 101 changed files with 605 additions and 2,035 deletions.
14 changes: 7 additions & 7 deletions .github/tour.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -ex
echo Clone tester repo.
git clone --single-branch --branch simplify https://github.com/John-LittleBearLabs/ipfs_client_clitester.git
git clone --single-branch --branch newmain https://github.com/John-LittleBearLabs/ipfs_client_clitester.git

echo Install dependencies.
sudo apt-get update
Expand All @@ -23,7 +23,7 @@ echo Build clitester
cmake --build tester_build --config Release

echo Start test server
( timeout 3600 python3 ./ipfs_chromium/test_data/test_server.py 8080 2>&1 | tee server.log & ) &
( timeout 600 python3 ./ipfs_chromium/test_data/test_server.py 8080 2>&1 | tee server.log & ) &
for t in 1{0..9}
do
if grep -n . server.log
Expand All @@ -42,8 +42,9 @@ function url_case() {
echo "path remaining =${2}"
echo "output hash =${3}"
echo "test case description =${4}"
echo "log level =${5-trace}"
if timeout 360 ./tester_build/clitester "${5-trace}" "${1}://${2}"
ll="${5-debug}"
echo "log level = ${ll}"
if timeout 360 ./tester_build/clitester "${ll}" "${1}://${2}"
then
echo clitester exited with successful status
else
Expand Down Expand Up @@ -79,11 +80,10 @@ function url_case() {
fi
}
url_case ipfs bafybeifx4tcpzbw7tzhwfbzsofgoana6cy7xbt64e3u6itve44c5zelpmm/symlinks/sub/dotdot.txt cfe9b69523140b5b5e63874a8e4997e4 'A symbolic link whose target includes ..'
url_case ipfs bafkqacdjmrsw45djor4q ff483d1ff591898a9942916050d2ca3f 'Identity (inlined) CID'
url_case ipfs baguqeerah2nswg7r2pvlpbnsz5y4c4pr4wsgbzixdl632w5qxvedqzryf54q 7750fd7b0928f007e1d181763c0dbdb5 'A DAG-JSON document. The block itself md5s to b92348005af4ae4795e6f312844fb359, but the response we are hashing here is an HTML preview page. This does mean this test breaks if you make the preview less ugly.'
url_case ipns en.wikipedia-on-ipfs.org/I/HFE_Too_Slow_1.JPG.webp 09c09b2654e8529740b5a7625e39e0c8 'An image fetched through DNSLink and HAMT sharded directories.'
url_case ipns en.wikipedia-on-ipfs.org/I/HFE_Too_Slow_1.JPG.webp 09c09b2654e8529740b5a7625e39e0c8 'An image fetched through DNSLink and HAMT sharded directories.' note
echo 'Skip as it takes too long.' url_case ipfs bafybeieb33pqideyl5ncd33kho622thym5rqv6sujrmelcuhkjlf2hdpu4/Big%20Buck%20Bunny.webm 06d51286e56badb4455594ebed6daba2 'A large UnixFS file - several hundred blocks.' error
url_case ipns k51qzi5uqu5dijv526o4z2z10ejylnel0bfvrtw53itcmsecffo8yf0zb4g9gi/symlinks/relative_link.txt cfe9b69523140b5b5e63874a8e4997e4 'A relative symlink resolves successfully to the file pointed to.'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ CMakeLists.txt.user
CMakeUserPresets.json
*.orig
.*.swp
gotit.json
3 changes: 1 addition & 2 deletions chromium_edits/120.0.6099.200/url/url_canon_ipfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ bool url::CanonicalizeIpfsURL(const char* spec,
Parsed parsed_input;
ParseStandardURL(spec, spec_len, &parsed_input);
return CanonicalizeStandardURL(
spec,
spec_len,
spec, spec_len,
parsed_input,
scheme_type,
charset_converter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 0fb94c9b9b67e..df25995c80baa 100644
index 655429c1daa7b..388d452cabc73 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -40,6 +40,7 @@ import("//rlz/buildflags/buildflags.gni")
Expand All @@ -10,11 +10,23 @@ index 0fb94c9b9b67e..df25995c80baa 100644
import("//third_party/protobuf/proto_library.gni")
import("//third_party/webrtc/webrtc.gni")
import("//third_party/widevine/cdm/widevine.gni")
@@ -2596,6 +2597,10 @@ static_library("browser") {
@@ -1944,7 +1945,6 @@ static_library("browser") {
"user_education/user_education_service_factory.h",
]
}
-
configs += [
"//build/config/compiler:wexit_time_destructors",
"//build/config:precompiled_headers",
@@ -2632,6 +2632,14 @@ static_library("browser") {
]
}

+ if (enable_ipfs) {
+ sources += [
+ "ipfs_extra_parts.cc",
+ "ipfs_extra_parts.h",
+ ]
+ deps += [ "//components/ipfs" ]
+ }
+
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 52ecc40da0226..42d45b977471e 100644
index ae88943acc26f..d1550497d6659 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -213,6 +213,7 @@
Expand All @@ -21,7 +21,7 @@ index 52ecc40da0226..42d45b977471e 100644
#if BUILDFLAG(ENABLE_PDF)
#include "pdf/pdf_features.h"
#endif
@@ -9851,6 +9856,14 @@ const FeatureEntry kFeatureEntries[] = {
@@ -9869,6 +9874,14 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kOmitCorsClientCertDescription, kOsAll,
FEATURE_VALUE_TYPE(network::features::kOmitCorsClientCert)},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index a9b87ac2fcd74..987686c621664 100644
index a9b87ac2fcd74..db78adcdce85c 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -377,6 +377,7 @@
Expand All @@ -10,11 +10,12 @@ index a9b87ac2fcd74..987686c621664 100644
#include "third_party/widevine/cdm/buildflags.h"
#include "ui/base/clipboard/clipboard_format_type.h"
#include "ui/base/l10n/l10n_util.h"
@@ -499,6 +500,12 @@
@@ -499,6 +500,13 @@
#include "chrome/browser/fuchsia/chrome_browser_main_parts_fuchsia.h"
#endif

+#if BUILDFLAG(ENABLE_IPFS)
+#include "chrome/browser/ipfs_extra_parts.h"
+#include "components/ipfs/interceptor.h"
+#include "components/ipfs/ipfs_features.h"
+#include "components/ipfs/url_loader_factory.h"
Expand All @@ -23,7 +24,19 @@ index a9b87ac2fcd74..987686c621664 100644
#if BUILDFLAG(IS_CHROMEOS)
#include "base/debug/leak_annotations.h"
#include "chrome/browser/apps/app_service/app_install/app_install_navigation_throttle.h"
@@ -6157,12 +6164,23 @@ void ChromeContentBrowserClient::
@@ -1785,6 +1793,11 @@ ChromeContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) {
main_parts->AddParts(
std::make_unique<ChromeBrowserMainExtraPartsNaclDeprecation>());

+#if BUILDFLAG(ENABLE_IPFS)
+ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) {
+ main_parts->AddParts(std::make_unique<IpfsExtraParts>());
+ }
+#endif
return main_parts;
}

@@ -6157,12 +6170,25 @@ void ChromeContentBrowserClient::
const absl::optional<url::Origin>& request_initiator_origin,
NonNetworkURLLoaderFactoryMap* factories) {
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \
Expand All @@ -38,18 +51,20 @@ index a9b87ac2fcd74..987686c621664 100644
+#if BUILDFLAG(ENABLE_IPFS)
+ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) {
+ network::mojom::URLLoaderFactory* default_factory = g_browser_process->system_network_context_manager()->GetURLLoaderFactory();
+ auto* context = web_contents->GetBrowserContext();
+ ipfs::IpfsURLLoaderFactory::Create(
+ factories,
+ web_contents->GetBrowserContext(),
+ context,
+ default_factory,
+ GetSystemNetworkContext()
+ GetSystemNetworkContext(),
+ Profile::FromBrowserContext(context)->GetPrefs()
+ );
+ }
+#endif // BUILDFLAG(ENABLE_IPFS)

#if BUILDFLAG(IS_CHROMEOS_ASH)
if (web_contents) {
@@ -6304,6 +6322,11 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
@@ -6304,6 +6330,11 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner) {
std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
interceptors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json
index 5e02e86a700cb..1f06bded184bf 100644
index 34def551f4809..d79463d5f1647 100644
--- a/chrome/browser/flag-metadata.json
+++ b/chrome/browser/flag-metadata.json
@@ -2956,6 +2956,11 @@
@@ -2954,6 +2954,11 @@
"owners": [ "[email protected]", "[email protected]" ],
"expiry_milestone": 130
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
index d6073d3514930..f80f1330f9865 100644
index 96296f3fc19ba..248436db82f5e 100644
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -288,6 +288,11 @@ const char kEnableBenchmarkingDescription[] =
@@ -294,6 +294,11 @@ const char kEnableBenchmarkingDescription[] =
"after 3 restarts. On the third restart, the flag will appear to be off "
"but the effect is still active.";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
index 4df49302f94b5..f7d3b65112d8b 100644
index db57d73eef1a4..c09e291a54494 100644
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -23,6 +23,7 @@
Expand All @@ -10,7 +10,7 @@ index 4df49302f94b5..f7d3b65112d8b 100644

// This file declares strings used in chrome://flags. These messages are not
// translated, because instead of end-users they target Chromium developers and
@@ -179,6 +180,11 @@ extern const char kDownloadWarningImprovementsDescription[];
@@ -182,6 +183,11 @@ extern const char kDownloadWarningImprovementsDescription[];
extern const char kEnableBenchmarkingName[];
extern const char kEnableBenchmarkingDescription[];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index fc9fcf1ff478a..800961b3c8767 100644
index 2c9e95b07c762..bb7affe8bdb66 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -190,6 +190,7 @@
Expand All @@ -22,7 +22,7 @@ index fc9fcf1ff478a..800961b3c8767 100644
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
#include "chrome/browser/screen_ai/pref_names.h"
#endif
@@ -1658,6 +1664,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
@@ -1728,6 +1734,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
IncognitoModePrefs::RegisterProfilePrefs(registry);
invalidation::PerUserTopicSubscriptionManager::RegisterProfilePrefs(registry);
invalidation::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ index 667370e623970..c09550c753e8e 100644
RenderFrameHost::FromID(render_process_id, render_frame_id);
WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host);
#endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \
// !BUILDFLAG(IS_ANDROID)
- // !BUILDFLAG(IS_ANDROID)
+ // !BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_IPFS)
+#if BUILDFLAG(ENABLE_IPFS)
+ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) {
+ network::mojom::URLLoaderFactory* default_factory = g_browser_process->system_network_context_manager()->GetURLLoaderFactory();
Expand Down
8 changes: 5 additions & 3 deletions cmake/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def create_patch_file(self):
self.git(['add', 'url/url_canon_ipfs.cc'], Result.OrDie)
diff = self.git(['diff', '--patch', tag], Result.RawOutput)
file_name = join(self.pdir, name+'.patch')
print('Old patch file:', file_name)
with open(file_name, 'w') as patch_file:
patch_file.write(diff+"\n")
# print('Old patch file:', file_name)
# with open(file_name, 'w') as patch_file:
# patch_file.write(diff+"\n")

def file_in_branch(self, ref: str, path: str):
out = self.git(['ls-tree', '--name-only', ref, path], Result.Output)
Expand Down Expand Up @@ -290,6 +290,8 @@ def out_of_date(self, p):
if not isdir(dir_path):
return True
file_path = f'{self.pdir}/{p}.patch'
if not isfile(file_path):
return False
with open(file_path) as f:
lines = f.readlines()
if not Patcher.has_file_line(lines, 'chrome/browser/flag-metadata.json', '+ "name": "enable-ipfs",'):
Expand Down
8 changes: 3 additions & 5 deletions component/cache_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ void Self::StartFetch(Task& task, net::RequestPriority priority) {
}
void Self::Miss(Task& task) {
if (task.request) {
VLOG(1) << "Cache miss on '" << task.request->Key() << "' for "
<< task.request->debug_string();
auto req = task.request;
task.request->Hook([this, req](std::string_view bytes) {
Store(req->Key(), "TODO", std::string{bytes});
Expand Down Expand Up @@ -145,8 +143,8 @@ void Self::OnBodyRead(Task task, int code) {
}
}
void Self::Store(std::string key, std::string headers, std::string body) {
LOG(INFO) << "Store(" << name() << ',' << key << ',' << headers.size() << ','
<< body.size() << ')';
VLOG(2) << "Store(" << name() << ',' << key << ',' << headers.size() << ','
<< body.size() << ')';
auto bound = base::BindOnce(&Self::OnEntryCreated, base::Unretained(this),
key, headers, body);
auto res = cache_->OpenOrCreateEntry(key, net::LOW, std::move(bound));
Expand Down Expand Up @@ -188,7 +186,7 @@ void Self::OnHeaderWritten(scoped_refptr<net::StringIOBuffer> buf,
buf = base::MakeRefCounted<net::StringIOBuffer>(body);
DCHECK(buf);
auto f = [](scoped_refptr<net::StringIOBuffer>, int c) {
VLOG(1) << "body write " << c;
VLOG(2) << "body write " << c;
};
auto bound = base::BindOnce(f, buf);
entry->WriteData(1, 0, buf.get(), buf->size(), std::move(bound), true);
Expand Down
15 changes: 5 additions & 10 deletions component/chromium_ipfs_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,12 @@ std::string Self::MimeType(std::string extension,
auto fp_ext = base::FilePath::FromUTF8Unsafe(extension).value();
if (extension.empty()) {
result.clear();
} else if (net::GetWellKnownMimeTypeFromExtension(fp_ext, &result)) {
VLOG(2) << "Got " << result << " from extension " << extension << " for "
<< url;
} else {
} else if (!net::GetWellKnownMimeTypeFromExtension(fp_ext, &result)) {
result.clear();
}
auto head_size = std::min(content.size(), 999'999UL);
if (net::SniffMimeType({content.data(), head_size}, GURL{url}, result,
net::ForceSniffFileUrlsForHtml::kDisabled, &result)) {
VLOG(2) << "Got " << result << " from content of " << url;
}
net::SniffMimeType({content.data(), head_size}, GURL{url}, result,
net::ForceSniffFileUrlsForHtml::kDisabled, &result);
if (result.empty() || result == "application/octet-stream") {
net::SniffMimeTypeFromLocalData({content.data(), head_size}, &result);
VLOG(2) << "Falling all the way back to content type " << result;
Expand All @@ -66,8 +61,8 @@ void Self::SendDnsTextRequest(std::string host,
DnsTextResultsCallback res,
DnsTextCompleteCallback don) {
if (dns_reqs_.find(host) != dns_reqs_.end()) {
LOG(ERROR) << "Requested resolution of DNSLink host " << host
<< " multiple times.";
LOG(WARNING) << "Requested resolution of DNSLink host " << host
<< " multiple times.";
}
auto don_wrap = [don, this, host]() {
don();
Expand Down
2 changes: 1 addition & 1 deletion component/dns_txt_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ void Self::OnComplete(int32_t result,
const ::net::ResolveErrorInfo&,
const absl::optional<::net::AddressList>&,
const absl::optional<Endpoints>&) {
VLOG(1) << "DNS Results done with code: " << result;
VLOG(2) << "DNS Results done with code: " << result;
completion_callback_();
}
9 changes: 4 additions & 5 deletions component/ipfs_url_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void ipfs::IpfsUrlLoader::FollowRedirect(

void ipfs::IpfsUrlLoader::SetPriority(net::RequestPriority priority,
int32_t intra_prio_val) {
VLOG(1) << "TODO SetPriority(" << priority << ',' << intra_prio_val << ')';
VLOG(2) << "TODO SetPriority(" << priority << ',' << intra_prio_val << ')';
}

void ipfs::IpfsUrlLoader::PauseReadingBodyFromNet() {
Expand Down Expand Up @@ -73,7 +73,6 @@ void ipfs::IpfsUrlLoader::StartRequest(
auto cid_str = resource_request.url.host();
auto path = resource_request.url.path();
auto abs_path = "/" + ns + "/" + cid_str + path;
VLOG(2) << resource_request.url.spec() << " -> " << abs_path;
me->root_ = cid_str;
me->api_->SetLoaderFactory(*(me->lower_loader_factory_));
auto whendone = [me](IpfsRequest const& req, ipfs::Response const& res) {
Expand Down Expand Up @@ -110,7 +109,7 @@ void ipfs::IpfsUrlLoader::AddHeader(std::string_view a, std::string_view b) {
}

void ipfs::IpfsUrlLoader::BlocksComplete(std::string mime_type) {
VLOG(1) << "Resolved from unix-fs dag a file of type: " << mime_type
VLOG(2) << "Resolved from unix-fs dag a file of type: " << mime_type
<< " will report it as " << original_url_;
if (complete_) {
return;
Expand All @@ -127,7 +126,7 @@ void ipfs::IpfsUrlLoader::BlocksComplete(std::string mime_type) {
head->mime_type = mime_type;
}
std::uint32_t byte_count = partial_block_.size();
VLOG(1) << "Calling WriteData(" << byte_count << ")";
VLOG(2) << "Calling WriteData(" << byte_count << ")";
pipe_prod_->WriteData(partial_block_.data(), &byte_count,
MOJO_BEGIN_WRITE_DATA_FLAG_ALL_OR_NONE);
VLOG(2) << "Called WriteData(" << byte_count << ")";
Expand All @@ -141,7 +140,7 @@ void ipfs::IpfsUrlLoader::BlocksComplete(std::string mime_type) {
auto* reason =
net::GetHttpReasonPhrase(static_cast<net::HttpStatusCode>(status_));
auto status_line = base::StringPrintf("HTTP/1.1 %d %s", status_, reason);
VLOG(1) << "Returning with status line '" << status_line << "'.\n";
VLOG(2) << "Returning with status line '" << status_line << "'.\n";
head->headers->ReplaceStatusLine(status_line);
if (mime_type.size()) {
head->headers->SetHeader("Content-Type", mime_type);
Expand Down
Loading

0 comments on commit 41fddd8

Please sign in to comment.