-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
Showing a NPE, debugging now, and will update the PR |
fixed NPE around getting a null body |
switch to SQLCipher
Awesome work, so glad someone tackled this! |
There was a problem hiding this 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' |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 ""; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
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.