Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix application crash when calculating the path length due to invalid UTF characters #1193

Merged
merged 5 commits into from
Dec 20, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 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,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);
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 {
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