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

okhttp3 3.12.x parse Part BUG #4564

Closed
lx0758 opened this issue Jan 17, 2019 · 8 comments
Closed

okhttp3 3.12.x parse Part BUG #4564

lx0758 opened this issue Jan 17, 2019 · 8 comments
Labels
bug Bug in existing code
Milestone

Comments

@lx0758
Copy link

lx0758 commented Jan 17, 2019

Good bug reports include a failing test! Writing a test helps you to isolate and describe the problem, and it helps us to fix it fast. Bug reports without a failing test or reproduction steps are likely to be closed.

Here’s an example test to get you started.
https://gist.github.com/swankjesse/981fcae102f513eb13ed

Version :

3.12.x

Error description :

When the MultipartBody.Part.createFormData(String name, @Nullable String filename, RequestBody body) method is called, if the file name contains Chinese, an IllegalArgumentException will be thrown to locate the calling chain:

MultipartBody.Part.createFormData(String name, @Nullable String filename, RequestBody body) 
Headers.of(String... namesAndValues)
Headers.checkValue(String value, String name)

The final code is as follows:

  static void checkValue(String value, String name) {
    if (value == null) throw new NullPointerException("value for name " + name + " == null");
    for (int i = 0, length = value.length(); i < length; i++) {
      char c = value.charAt(i);
      if ((c <= '\u001f' && c != '\t') || c >= '\u007f') {
        throw new IllegalArgumentException(Util.format(
            "Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value));
      }
    }
  }

As shown above, this code does not handle Chinese correctly.

@lx0758 lx0758 added the bug Bug in existing code label Jan 17, 2019
@lx0758
Copy link
Author

lx0758 commented Jan 25, 2019

@swankjesse

@swankjesse
Copy link
Collaborator

Related to #3876

Should confirm we got all cases.

@valepakh
Copy link

Is it possible to backport this to 3.12.x?

valepakh pushed a commit to valepakh/okhttp that referenced this issue Feb 15, 2019
@swankjesse
Copy link
Collaborator

@valepakh pull request?

@Movill-Tony-p
Copy link

Movill-Tony-p commented May 2, 2019

@swankjesse my application support android4.x but this bug very critical
can't send multipart Korean file name
need backport this to 3.12.x

@swankjesse
Copy link
Collaborator

@Movill-Tony-p awesome. Please do.

@valepakh
Copy link

valepakh commented May 2, 2019

@swankjesse I actually filed pull request #4618 a while back, it works ok, just doesn't pass the build due to the java changes.

@lognaturel
Copy link

Thanks so much for this backport, @valepakh, and for the merge, @swankjesse. You're helping folks collect data in challenging environments (and languages with Unicode characters). 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

5 participants