miketeo/pysmb

Issue with unicode paths decoding

althonos opened this issue · 6 comments

Hi ! While developing fs.smbfs, I encountered the following issue:

after creating a folder called földér, and within it a file called ☣.txt (yes I'm having a lot of fun on my free time), the SMBConnection.getAttributes("myshare", "földér/☣.txt") returns an object, allright, but its filename attribute is 'földér\\☣.txt' instead of '☣.txt' !

I checked using an external client, and both the file and the folder are properly created, so this issue only occurs in getAttributes.

Still, I'd like to thank you for this great library !

@althonos : May I know what is the OS / smb service that you are using on the server end?

I used two different servers that both got the same result:

  • the native SMB server built into my Freebox (web router / local NAS)
  • the pwntr/samba-alpine docker image running locally

If you want to spawn it, this is the command I used:

mkdir /tmp/samba
docker run --rm -it --net=host -v /tmp/samba:/shared --name samba pwntr/samba-alpine

Issue should then be reproductible:

import io
from smb.SMBConnection import SMBConnection

server = SMBConnection('rio', 'letsdance', 'ME', 'SAMBASERVER')
server.connect('127.0.0.1')
server.createDirectory('data', 'földér')
server.storeFile('data', '/földér/☣.txt', io.BytesIO(b'biohazard'))

# If here you check /tmp/samba, both the folder and the file
# will be present without name / encoding issue

# And there is our issue
print("FILENAME:", server.getAttributes('data', '/földér/☣.txt').filename)
# this prints 'földér\\☣.txt'
divad commented

Freebox uses Samba too

divad commented

So I ran your code on Python 3 and I got the expected result:

FILENAME: test\földér\☣.txt

Against Samba 4.6.7 on Arch Linux

Were you running on Python 2 or 3?

@althonos : Fixed in pysmb 1.1.22.

Fixed indeed. Thanks.