Skip to content

Commit

Permalink
Fix application crash when calculating the path length due to invalid…
Browse files Browse the repository at this point in the history
… UTF characters (#1193)

* Fix application crash when calculating the path length due to invalid UTF characters
  • Loading branch information
abraunegg authored Dec 20, 2020
1 parent 3341e30 commit 771a932
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -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"){
Expand All @@ -3698,19 +3698,31 @@ 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);
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/487
// 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;
}

Expand Down

0 comments on commit 771a932

Please sign in to comment.