Skip to content
Snippets Groups Projects
Commit 066624d5 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

conversationrepository: fix "too big to fetch" error

stats->received_bytes contains the received size from the beginning
not per pack object. So, the previous check was incorrectly done
as it was checking an incorrect size.

GitLab: #768
Change-Id: I83dcda28298bcfc4c9c1c53f8639fa290f241307
parent 51b10199
No related branches found
No related tags found
No related merge requests found
...@@ -2500,14 +2500,15 @@ ConversationRepository::cloneConversation(const std::weak_ptr<JamiAccount>& acco ...@@ -2500,14 +2500,15 @@ ConversationRepository::cloneConversation(const std::weak_ptr<JamiAccount>& acco
git_clone_options clone_options; git_clone_options clone_options;
git_clone_options_init(&clone_options, GIT_CLONE_OPTIONS_VERSION); git_clone_options_init(&clone_options, GIT_CLONE_OPTIONS_VERSION);
git_fetch_options_init(&clone_options.fetch_opts, GIT_FETCH_OPTIONS_VERSION); git_fetch_options_init(&clone_options.fetch_opts, GIT_FETCH_OPTIONS_VERSION);
size_t received_bytes = 0;
clone_options.fetch_opts.callbacks.payload = static_cast<void*>(&received_bytes);
clone_options.fetch_opts.callbacks.transfer_progress = [](const git_indexer_progress* stats, clone_options.fetch_opts.callbacks.transfer_progress = [](const git_indexer_progress* stats,
void* payload) { void*) {
*(static_cast<size_t*>(payload)) += stats->received_bytes; // Uncomment to get advancment
if (*(static_cast<size_t*>(payload)) > MAX_FETCH_SIZE) { // if (stats->received_objects % 500 == 0 || stats->received_objects == stats->total_objects)
JAMI_ERR("Abort fetching repository, the fetch is too big: %lu bytes", // JAMI_DEBUG("{}/{} {}kb", stats->received_objects, stats->total_objects, stats->received_bytes/1024);
*(static_cast<size_t*>(payload))); // If a pack is more than 256Mb, it's anormal.
if (stats->received_bytes > MAX_FETCH_SIZE) {
JAMI_ERROR("Abort fetching repository, the fetch is too big: {} bytes ({}/{})",
stats->received_bytes, stats->received_objects, stats->total_objects);
return -1; return -1;
} }
return 0; return 0;
...@@ -2897,13 +2898,14 @@ ConversationRepository::fetch(const std::string& remoteDeviceId) ...@@ -2897,13 +2898,14 @@ ConversationRepository::fetch(const std::string& remoteDeviceId)
} }
GitRemote remote {remote_ptr, git_remote_free}; GitRemote remote {remote_ptr, git_remote_free};
size_t received_bytes = 0; fetch_opts.callbacks.transfer_progress = [](const git_indexer_progress* stats, void*) {
fetch_opts.callbacks.payload = static_cast<void*>(&received_bytes); // Uncomment to get advancment
fetch_opts.callbacks.transfer_progress = [](const git_indexer_progress* stats, void* payload) { // if (stats->received_objects % 500 == 0 || stats->received_objects == stats->total_objects)
*(static_cast<size_t*>(payload)) += stats->received_bytes; // JAMI_DEBUG("{}/{} {}kb", stats->received_objects, stats->total_objects, stats->received_bytes/1024);
if (*(static_cast<size_t*>(payload)) > MAX_FETCH_SIZE) { // If a pack is more than 256Mb, it's anormal.
JAMI_ERR("Abort fetching repository, the fetch is too big: %lu bytes", if (stats->received_bytes > MAX_FETCH_SIZE) {
*(static_cast<size_t*>(payload))); JAMI_ERROR("Abort fetching repository, the fetch is too big: {} bytes ({}/{})",
stats->received_bytes, stats->received_objects, stats->total_objects);
return -1; return -1;
} }
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment