Repository navigation
Ensure URL normalization is safe for all input. Fixes #2695 - #2804
Conversation
There was a problem hiding this comment.
This one should be pathname.size() < 4, since pathname[3] is used unconditionally.
There was a problem hiding this comment.
In this particular case, isDraft assumes a pathname longer than 3. That’s dead code now.
There was a problem hiding this comment.
This is in the wrong section: I've adjusted the code to < 4 for the glyph endpoint
039a54f to
e29967c
Compare
|
Addressed @jfirebaugh's issue, and added log messages as suggested by @1ec5: is it possible to test our log output? |
|
At a glance, I think assertions would be better than log messages in this case, because client code may assume “normalized” to mean “no more mapbox: URLs”. But this is definitely an improvement over the current behavior. |
|
@jfirebaugh should I merge this as-is or switch to assertions? |
|
One problem with asserts is that on Android it causes a native crash which confuses most Android devs as they are unlikely to have seen these before and will struggle to connect the crash to a malformed URL. I would much prefer logging, or even better a way to through a Java exception with a suitable error message. /cc @bleege |
|
I think it’s generally best to assert when the issue is likely to be developer error; logging and otherwise failing gracefully is better for issues out of the developer’s direct control, like network failures. The JNI code should have exception handling to catch assertions and present them as Java exceptions. |
|
Sounds like we should do logging first, and then the JNI work, and then switch to exceptions |
|
@1ec5 Unfortunately JNI was desinged before C++ exceptions were invented and there is no reliable way to pass them to Java. Even the exception's message is not printed on Android, all you get in the log is a SIGABRT error. I have tried various libs that claim to handle C++ exceptions in JNI, but they were either outdated (did not support newer Android versions), unreliable (missed most exceptions), or just complicated debugging normal crashes with false stack traces. Quite simply C++ exceptions are not compatible with Android. |
Agreed. However, "what JNI should do" vs "what JNI can actually do" are often 2 different things. 😄 Remember JNI is an imperfect (and usually one way) bridge between C++ code and Java code. |
|
When you interface with C++ code, you have to be open to exceptions being thrown, and not just for the most catastrophic of reasons. So it sounds like we need to revisit this issue, probably as another layer beneath JNI that catches C++-style exceptions and turns them into C-style error codes. We'd do the same if we wanted to expose these error conditions as native exceptions on the iOS side too. But saying the C++ layer can't use C++ exceptions because of JNI is like the tail wagging the dog. 😊 I don't want to hold up this PR for a seemingly large task, so this is good to go. |
e29967c to
2830e4f
Compare
|
LGTM. What @1ec5 says about exceptions is spot on -- when writing bindings to C++, it's common to need to blanket catch all exceptions and translate them into some other error mechanism that's compatible with the platform. |
|
I can see our jni.cpp growing in size :-( we really need to refactor that file into smaller ones. |
2830e4f to
c80c823
Compare
Check that a URL has enough segments before normalizing it.
cc @jfirebaugh for the review