Skip to content

Instantly share code, notes, and snippets.

@ncw
Last active March 25, 2016 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncw/1beadd7258ca87a6ca55 to your computer and use it in GitHub Desktop.
Save ncw/1beadd7258ca87a6ca55 to your computer and use it in GitHub Desktop.
Reproduction for OneDrive file corruption

File corruption bug on onedrive

To reproduce, run the python program onedrive_bug.py. This needs the python onedrivesdk. This uploades the file goof.png repeatedly, to the root of your onedrive as 1.png, 2.png, etc.

If you run it after a while you'll see a size mis-match.

This means that the 97k file is apparently 200k. If you look in the web interface it also appears as 200k, however if you download it is really only 97k.

I don't think this is a bug in the python library, rather a bug in Onedrive.

I think the bug depends on the particular file being uploaded.

A user of my program rclone ( @Darkvater )noticed the file corruptions originally here and supplied the png file which is used for the demo here.

rclone/rclone#399

This means that this bug has been reproduced with the Python SDK and my own Go SDK and from at least 4 different environments (computers, OS, net connections etc).

$ python onedrive_bug.py 
Created new window in existing browser session.
127.0.0.1 - - [25/Mar/2016 16:38:50] "GET /?code=xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx HTTP/1.1" 200 -
Uploaded test file: 0.png, size 97258
Uploaded test file: 1.png, size 97258
Uploaded test file: 2.png, size 97258
Uploaded test file: 3.png, size 97258
Uploaded test file: 4.png, size 97258
Uploaded test file: 5.png, size 97258
Uploaded test file: 6.png, size 205029
**** Size mismatch
Uploaded test file: 7.png, size 205029
Uploaded test file: 8.png, size 205029
Uploaded test file: 9.png, size 205029
Uploaded test file: 10.png, size 97258
**** Size mismatch
Uploaded test file: 11.png, size 97258
Uploaded test file: 12.png, size 97258
Uploaded test file: 13.png, size 97258

Nick Craig-Wood nick@craig-wood.com 2016-03-25

#!/usr/bin/env python
"""
This demonstrates a bug in onedrive
"""
import os
import onedrivesdk
from onedrivesdk.helpers import GetAuthCodeServer
import SocketServer
from datetime import datetime
SocketServer.TCPServer.allow_reuse_address = True # monkey patch so as to set SO_REUSEADDR
GetAuthCodeServer.allow_reuse_address = True
TEST_FILE="goof.png"
def main():
redirect_uri = "http://localhost:8080/"
client_secret = "BqaTYqI0XI7wDKcnJ5i3MvLwGcVsaMVM"
client = onedrivesdk.get_default_client(client_id='00000000481695BB',
scopes=['wl.signin',
'wl.offline_access',
'onedrive.readwrite'])
auth_url = client.auth_provider.get_auth_url(redirect_uri)
# Block thread until we have the code
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
# Finally, authenticate!
client.auth_provider.authenticate(code, redirect_uri, client_secret)
root = client.item(drive="me", id="root")
last_uploaded_size = None
for i in range(100):
name = "%d.png" % i
uploaded_file = root.children[name].upload(TEST_FILE)
print "Uploaded test file: %s, size %d" % (name, uploaded_file.size)
if last_uploaded_size != None:
if last_uploaded_size != uploaded_file.size:
print "**** Size mismatch"
last_uploaded_size = uploaded_file.size
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment