Incorrect DST handling when parsing file timestamps

Open
#267 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, linux, macos

Research direction

Start by locating the timestamp conversion code used on Windows and POSIX for old ZIP, RAR, and FAT timestamps. Compare the Windows APIs and POSIX mktime approach described in the issue, including the Windows 2000 compatibility constraint, then check existing timestamp tests or add cases for winter and summer dates. Done means conversions use the DST rule for the timestamp’s date and preserve the expected UTC time.

Written by the indexing model from the issue text.

Description

7-Zip uses LocalFileTimeToFileTime and FileTimeToLocalFileTime on Windows to convert between local time and UTC when working with formats that store timestamps in local time (old ZIP archives, RAR archives, FAT filesystems). The problem is, the former uses the current DST state to convert time instead of historical one, while the latter doesn't bother with accounting for DST at all. So, for example, if you're in Germany (UTC+1 during winter time) and you're on summer time, LocalFileTimeToFileTime will interpret all timestamps you pass into it as UTC+2, even something like January 5th, which should be interpreted as UTC+1. As such, extracting a file with such a modify date would result in the final timestamp being 1 hour off.

This affects Linux and Mac versions as well - while 7-Zip uses custom code there for conversion, it has the same problem where the current DST state is used instead of historical one.

On Windows, the solution is to use TzSpecificLocalTimeToSystemTime and SystemTimeToTzSpecificLocalTime, which do properly account for historical DST intervals, like was done here: https://github.com/dosbox-staging/dosbox-staging/pull/4339. The only problem is that TzSpecificLocalTimeToSystemTime does not exist on Windows 2000. On POSIX, I believe the proper course of action is to use mktime to find if DST was in effect during the specified local time.

Dominant language
C++
Stars
4.6k
Forks
519
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ip7z/7zip

All issues in ip7z/7zip

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.