-
Notifications
You must be signed in to change notification settings - Fork 553
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
Use libc rather than iana-time-zone on Android. #1148
Conversation
So I'm honestly not sure after the latest discussion in #1018 whether I still want to go with using |
Is this summary correct? The current solution in chrono is fine for most users, and avoids Reason is the use of chrono in the android project. The dependency A second reason is that the file format used for the timezone database on android is not guaranteed to be stable. It seems to me the benefits of being able to make use of the OS timezone database instead of shipping a database with an application, which can get outdated, outweigh the potention breakage in the future. It should not be too hard to update the parser to the new format. Maybe the use of |
Yeah, I think your summary is correct. On top of that, future versions of Android might come with a safer libc API to get at the timezone offset data.
Seems like a reasonable solution. |
These functions were added in Android API level 35, and provide a better interface to getting timezones, with no environment variable access to worry about.
f5b9836
to
efa2d54
Compare
I've updated this PR to include the code to try at runtime to find the new I disagree that "the current solution in chrono is fine for most users". Use of the system property as an API is not great, but depending on the format of the timezone database is worse (especially for applications outside of the platform) as it could change any time the database is updated, which happens fairly regularly. Suppose that a bunch of users have installed an application using chrono to handle timezones. The application works fine, until at some point in the future some country suddenly changes their daylight savings time rules in a way which requires new code to handle some new logic to handle. Android ships an update to the system timezone database, along with new parser code to handle it. All the applications using the supported APIs continue to work fine, but the application using chrono suddenly starts failing. To the users, it looks like Android just suddenly broke the application, but really the problem is that the application was using an unstable internal implementation detail rather than a supported API. As far as I know it's not possible with cargo to make adding a feature remove a dependency, like the suggested |
That sounds great!
I agree that the current situation is not great. But, Android is the platform here that has chosen to deviate from standard ways of exposing the current timezone and system timezone database. You seem to make an argument that the platform can ship a new system timezone database and new parser code to handle potential format changes in it -- if you can ship that, why can't you also ship APIs that expose that data to userspace with a better API at the same time? That would also solve this problem AFAICT. (Shipping the timezone database in a format that regularly has to change to accomodate updates seems problematic to me -- why is this format better than the format which all other Linux distributions use, whose format has changed ~never?)
Adding a feature like that seems reasonable to me. I don't think this would have to lead to some kind of combinatorial explosion of code paths, as you seem to suggest. |
On talking more to people internally about this, it sounds like I was partly wrong. Android doesn't generally make changes to the format and parser in mainline updates, usually just between releases. Still, the format is not guaranteed to be stable. And developers of Android applications probably want them to work correctly on devices running a range of different Android releases without having to rebuild them. Android does expose APIs to userspace to access the timezone data. The main ones are the Java APIs, which are not very helpful here unless we add a bunch of JNI code to chrono, which seems like something it would be best to avoid. The supported native APIs up to API level 34 are
From what I understand there are changes in other Linux distributions too. The syntax of the format is stable, but the semantics (i.e. what gets filled in and the meaning of what's there) is less stable. |
If the format is usually not changed between mainline updates, I think that means we're safe if we (a) keep the current strategy for current/old Android versions and (b) use the new |
I've added a feature, PTAL. Unfortunately it doesn't seem to be possible with cargo to completely avoid the |
I'm a maintainer of The library could be much smaller if Rust had weak symbols or if it dropped support for Android < 5. The former won't happen anytime soon. The latter would be a downgrade. (I guess you guys want to sell more new phones, so maybe it would be an upgrade to you.) ;) Your rustutils in fact does not seem to support Android < 5, does it? |
Did you already read all of the preceding discussion in #1018? |
This comment was marked as off-topic.
This comment was marked as off-topic.
There are two distinct cases that have somewhat different concerns: Rust code in the Android platform, and Rust code in Android applications. I work on the platform so my primary concern is with that, and the immediate issue I'm trying to solve is that we are blocked on updating the version of
The issue with |
@qwandor, thank you for the explanation! |
Android is just using concatenated TZif files if I understand it right, of which the format is just like Linux, macOS and the BSDs. There is RFC 8536 to describe the format. If worse comes to worse and there is some rule for future dates that can't be expressed, current practice is to just fall back to a long list of transition dates. This already happens for countries that adjust the clock around ramadan, which depends on the moon. I don't see the format breaking anytime soon. |
The nice thing about doing the calculations in chrono is that we can improve over what libc offers:
|
As far as I know they can choose whether to include |
@qwandor Just want to say that although I am doing difficult and don't like the direction, I appreciate your work. |
That is the current status of this PR? |
I added a feature flag in 3923d5c to revert to the old behaviour, this is awaiting review. |
Reintroducing CVE-2020-26235/RUSTSEC-2020-0159, which caused chrono a lot of pain (and moved a good number of users to time-rs which was earlier with a kind of fix), is not something to quickly step over. I still think the motivation 'we don't want to use With the changes to the documentation and the following discussion, keep in mind that for us it reads like: reintroduce CVE on android to avoid using an unstable API. I have to admit both are not great places to be in.
If we go with this approach this PR could make easier progress. |
I've opened an issue for using |
As discussed in #1018, this switches back to using
localtime_r
andmktime
from libc to get the local timezone on Android, rather than depending oniana-time-zone
and trying to parse Android's tzdata files directly. This is better because the tzdata file format is not stable, and we don't want to useiana-time-zone
in the Android platform.I'll send a separate PR to check for the availability of the new
localtime_rz
and friends and use them instead where possible.