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
Opening file on a share fails with STATUS_OBJECT_NAME_NOT_FOUND #452
Comments
At the moment SMBJ takes the UTF-16 byte sequence representing the file name from the message and attempts to decode it to a Java String. Then when you try to open the file it reencodes the Java String to a UTF-16 byte sequence again. In situations where the original input data is invalid UTF-16 you're going to get the replacement character code point and as a consequence the reencoded version may not be identical to the original. In other words, the The only way I can come up with to work around this is to hold on to the original 'raw' filename so that you can send it back to the server verbatim. |
To actually answer your question, this is kind of a bug when dealing with filenames that are not valid UTF-16. There's no workaround for this. Proper fix would require changing the internal representation of paths in SMBJ from String to something lower level that holds on to the original byte representation of the filename. |
@pepijnve , I appreciate your prompt reply. It sounds like there is no roundtrip conversion from UTF-16 to String and this explains the behavior. |
The round-trip works when all characters are valid UTF-16. In your case one of them isn't. |
@hierynomus yes, that's the case. |
Just checked the MS-SMB2 spec:
And for the SMB2 CREATE request:
This means that the filename must be valid UTF-16 in order to work. It seems that the server is not adhering to the spec. |
@mpohajac The sequence you provided, Would it be possible to provide a hexdump of the UTF-16 byte sequence that actually gets sent from the server instead? Wireshark, tcpdump or netsh packet capture would be ideal, but a hexdump from the Java code works too of course. |
@hierynomus , @pepijnve thanks for the info. These are the bytes from the wireshark for the Filename:
Four valid UTF-16 chars This is reproducible with:
|
@hierynomus how would you prefer to handle this case? Best option IMO is to use something like the SmbPath class everywhere that can wrap a raw I agree with you that what the server is sending is not 100% spec compliant, but that's just a fact of life we have to deal with. We see this kind of mess all the time, especially when data is written via NFS and then accessed via SMB. |
Hi,
Please let us know how to mitigate this? would you say this is a bug or we are doing something wrong? openFile works ok with pretty much any name except this one with strange characters. See description below.
Thank you,
Marko
Symptoms
Opening file on a share fails with the following error:
Cause
Bytes representation of file name "21 �a" is as follows: 323120EFBFBE61
When listing files with SMBJ the bytes representation of this particular file is slightly changed to: 323120EFBFBD61
-> Instead of EFBFBE, EFBFBD was used, which is a bytes representation of replacement character.
Since the file name gets changed, file could not be opened and fails with the above exception.
How to verify
Prerequisites
Attached problematic file "21 �a" resides on the share in the folder named "directory".
directory.zip
Steps to reproduce
Use the following code to reproduce the problem:
The text was updated successfully, but these errors were encountered: