Fix crash when resume_upload file is not a valid JSON (#664)

* Validate that there is JSON data in the string before the string is read via parseJSON()
* Add try block to catch file system exceptions if they are generated when attempting to update the file date & time
This commit is contained in:
abraunegg 2019-09-22 06:40:39 +10:00 committed by GitHub
parent 72467e32ca
commit fd4547376c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -1342,7 +1342,12 @@ final class SyncEngine
// handle changed time
if (newItem.type == ItemType.file && oldItem.mtime != newItem.mtime) {
setTimes(newPath, newItem.mtime, newItem.mtime);
try {
setTimes(newPath, newItem.mtime, newItem.mtime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg);
}
}
}
}
@ -1457,7 +1462,12 @@ final class SyncEngine
if ((getSize(path) == fileSize) || (OneDriveFileHash == quickXorHash) || (OneDriveFileHash == sha1Hash)) {
// downloaded matches either size or hash
log.vdebug("Downloaded file matches reported size and or reported file hash");
setTimes(path, item.mtime, item.mtime);
try {
setTimes(path, item.mtime, item.mtime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg);
}
} else {
// size error?
if (getSize(path) != fileSize) {

View file

@ -62,7 +62,16 @@ struct UploadSession
{
if (exists(sessionFilePath)) {
log.vlog("Trying to restore the upload session ...");
session = readText(sessionFilePath).parseJSON();
// We cant use JSONType.object check, as this is currently a string
// We cant use a try & catch block, as it does not catch std.json.JSONException
auto sessionFileText = readText(sessionFilePath);
if(canFind(sessionFileText,"@odata.context")) {
session = readText(sessionFilePath).parseJSON();
} else {
log.vlog("Upload session resume data is invalid");
remove(sessionFilePath);
return false;
}
// Check the session resume file for expirationDateTime
if ("expirationDateTime" in session){