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

CheckCharset on PostData to prevent hanging or crashing #564

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

thebehera
Copy link

This should resolve the error around: #329
Use CharsetDecoder to decode the byte[]. if it reports an error, bail out and report to the chrome inspector that Charset in POST/PUT is not UTF-8. Data (length:X) cannot be represented as a string.

@thebehera
Copy link
Author

Showing a NPE, debugging now, and will update the PR

@thebehera thebehera closed this Sep 18, 2017
@thebehera
Copy link
Author

fixed NPE around getting a null body

@thebehera thebehera reopened this Sep 18, 2017
@jasta
Copy link
Contributor

jasta commented Dec 28, 2017

Awesome work, so glad someone tackled this!

Copy link
Contributor

@jasta jasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the unrelated changes and some minor cleanup and we should be good to go! Thanks again!

@@ -19,6 +19,7 @@ dependencies {
compile 'com.google.code.findbugs:jsr305:2.0.1'

compile 'com.android.support:appcompat-v7:23.0.1' // optional
compile 'net.zetetic:android-database-sqlcipher:3.5.7@aar'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You appear to have a number of unrelated changes here that should be removed. Also an aside, you don't need this SQLCipher thing directly in Stetho as you can just install your own DatabaseDriver2 implementation now (see SqliteDatabaseDriver and work from there as needed).

@@ -39,6 +48,8 @@

private static NetworkEventReporter sInstance;

private static final CharsetDecoder decoder = Charset.forName(Utf8Charset.NAME).newDecoder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a non-static member variable and initialize it in the constructor. No need to muck up the get() method below.

if (body != null) {
return new String(body, Utf8Charset.INSTANCE);
if (body == null || body.length == 0) {
return "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to return null if body was null before. Should it still?

Console.MessageLevel.WARNING,
Console.MessageSource.NETWORK,
logMessage + e);
return logMessage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I like returning the log message here, but it suggests actually that we'd be better off merging the error cases below:

try {
 // decode...
} catch (IOException | OutOfMemoryError e) {
  String error = determineErrorMessage(e);
  CLog.writeToConsole("Could not reproduce POST/PUT body: " + error);
  return error;
}

Then determineErrorMessage could peak and see if it's a CharsetCodingException and craft your better error message above.

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

Successfully merging this pull request may close these issues.

4 participants