From 72a1de4d4b8241e29dd7e0b6b5c0c79b3001d50f Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sat, 19 Dec 2020 07:02:01 +1100 Subject: [PATCH 1/4] Fix application crash when calculating the path length due to invalid UTF characters * Fix application crash when calculating the path length due to invalid UTF characters --- src/sync.d | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/sync.d b/src/sync.d index d2ae8cf8e..b8deac2dd 100644 --- a/src/sync.d +++ b/src/sync.d @@ -3682,13 +3682,13 @@ final class SyncEngine { import std.range : walkLength; import std.uni : byGrapheme; - // https://support.microsoft.com/en-us/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders - // If the path is greater than allowed characters, then one drive will return a '400 - Bad Request' - // Need to ensure that the URI is encoded before the check is made - // 400 Character Limit for OneDrive Business / Office 365 - // 430 Character Limit for OneDrive Personal + // https://support.microsoft.com/en-us/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders + // If the path is greater than allowed characters, then one drive will return a '400 - Bad Request' + // Need to ensure that the URI is encoded before the check is made + // 400 Character Limit for OneDrive Business / Office 365 + // 430 Character Limit for OneDrive Personal long maxPathLength = 0; - long pathWalkLength = path.byGrapheme.walkLength; + long pathWalkLength = 0; // Configure maxPathLength based on account type if (accountType == "personal"){ @@ -3698,19 +3698,30 @@ final class SyncEngine // Business Account / Office365 maxPathLength = 400; } - - // A short lived file that has disappeared will cause an error - is the path valid? - if (!exists(path)) { - log.log("Skipping item - has disappeared: ", path); + + // Calculate the path length by walking the path, catch any UTF-8 character errors + // https://github.com/abraunegg/onedrive/issues/1192 + try { + pathWalkLength = path.byGrapheme.walkLength; + } catch (std.utf.UTFException e) { + // path contains characters which generate a UTF exception + log.vlog("Skipping item - invalid UTF sequence: ", path); + log.vdebug(" Error Reason:", e.msg); return; } - // Invalid UTF-8 sequence check + // check the std.encoding of the path // https://github.com/skilion/onedrive/issues/57 // https://github.com/abraunegg/onedrive/issues/487 if(!isValid(path)) { // Path is not valid according to https://dlang.org/phobos/std_encoding.html - log.vlog("Skipping item - invalid character sequences: ", path); + log.vlog("Skipping item - invalid character encoding sequence: ", path); + return; + } + + // A short lived file that has disappeared will cause an error - is the path valid? + if (!exists(path)) { + log.log("Skipping item - path has disappeared: ", path); return; } From 22404a8a0e069b8218d91447145fd80c5ef1602d Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 21 Dec 2020 07:14:09 +1100 Subject: [PATCH 2/4] Update sync.d * The has path has disappeared check needs to be first --- src/sync.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sync.d b/src/sync.d index b8deac2dd..648046413 100644 --- a/src/sync.d +++ b/src/sync.d @@ -3699,6 +3699,12 @@ final class SyncEngine maxPathLength = 400; } + // A short lived file that has disappeared will cause an error - is the path valid? + if (!exists(path)) { + log.log("Skipping item - path has disappeared: ", path); + return; + } + // Calculate the path length by walking the path, catch any UTF-8 character errors // https://github.com/abraunegg/onedrive/issues/1192 try { @@ -3719,12 +3725,6 @@ final class SyncEngine return; } - // A short lived file that has disappeared will cause an error - is the path valid? - if (!exists(path)) { - log.log("Skipping item - path has disappeared: ", path); - return; - } - // Is the path length is less than maxPathLength if(pathWalkLength < maxPathLength){ // skip dot files if configured From 02ef5e466a2fda588ee1c26c07f0987ca1ec52db Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 21 Dec 2020 07:15:44 +1100 Subject: [PATCH 3/4] Update sync.d * Fix up comments --- src/sync.d | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sync.d b/src/sync.d index 648046413..0a804169b 100644 --- a/src/sync.d +++ b/src/sync.d @@ -3683,10 +3683,10 @@ final class SyncEngine import std.range : walkLength; import std.uni : byGrapheme; // https://support.microsoft.com/en-us/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders - // If the path is greater than allowed characters, then one drive will return a '400 - Bad Request' - // Need to ensure that the URI is encoded before the check is made - // 400 Character Limit for OneDrive Business / Office 365 - // 430 Character Limit for OneDrive Personal + // If the path is greater than allowed characters, then one drive will return a '400 - Bad Request' + // Need to ensure that the URI is encoded before the check is made: + // - 400 Character Limit for OneDrive Business / Office 365 + // - 430 Character Limit for OneDrive Personal long maxPathLength = 0; long pathWalkLength = 0; From 1d1dbd4b6d84ce1ee6b8cc4cece5aa958c18d385 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 21 Dec 2020 07:17:56 +1100 Subject: [PATCH 4/4] Update sync.d * Update comments --- src/sync.d | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sync.d b/src/sync.d index 0a804169b..f21322df3 100644 --- a/src/sync.d +++ b/src/sync.d @@ -3706,6 +3706,7 @@ final class SyncEngine } // Calculate the path length by walking the path, catch any UTF-8 character errors + // https://github.com/abraunegg/onedrive/issues/487 // https://github.com/abraunegg/onedrive/issues/1192 try { pathWalkLength = path.byGrapheme.walkLength;