#1035375 mtools: interprets SOURCE_DATE_EPOCH in system timezone instead of UTC

Package:
mtools
Source:
mtools
Description:
Tools for manipulating MSDOS files
Submitter:
Alper Nebi Yasak
Date:
2025-08-03 21:31:01 UTC
Severity:
normal
Tags:
#1035375#5
Date:
2023-05-02 11:00:44 UTC
From:
To:
Hi,

I came across timestamp differences in FAT filesystem images while
trying to build debian-installer with debrepro (among many other
things), and tracked it down to mmd/mcopy calls. Here's a short reproducer:

  export SOURCE_DATE_EPOCH="$(date "+%s")"

  imgprep() {
    [ -f "$1" ] && rm "$1"
    mkfs.msdos --invariant -v -i deb00001 -C "$1" 512
    mmd -i "$1" ::foo
    mcopy -i "$1" "$2" ::bar
  }

  dd if=/dev/random of=rand.img bs=512 count=200

  TZ=UTC   imgprep first.img rand.img
  TZ=UTC-3 imgprep second.img rand.img

  diffoscope first.img second.img

which shows an exact 3-hour difference in timestamps for me. AFAICT,
SOURCE_DATE_EPOCH is meant to be in UTC, so embedded timestamps and the
two files should be the same regardless of TZ or system timezone.

#1035375#10
Date:
2023-05-02 17:57:18 UTC
From:
To:
tags 1035375 + patch
forwarded 1035375 https://lists.gnu.org/archive/html/info-mtools/2023-05/msg00000.html
thanks

Hi Alper,

Ah, interesting! And your reproducer is extremely helpful, and
I've managed to put together a proof-of-concept patch:

#1035375#19
Date:
2023-12-07 00:32:05 UTC
From:
To:
Did that get a response from upstream?

Seems like a simple patch with limited chance of introducing
problems... maybe a slightly more complicated veresion that only does
this when SOURCE_DATE_EPOCH is set.

Maybe it could be applied to the debian mtools package to at least give
it some real-world testing? :)

live well,
  vagrant

#1035375#24
Date:
2025-07-07 10:29:11 UTC
From:
To:
Hi mtools maintainers, Alain,

it appears the patch posted in 2023 to fix SOURCE_DATE_EPOCH support
under non-UTC TZ never made it anywhere. It was posted here:
https://lists.gnu.org/archive/html/info-mtools/2023-05/msg00000.html

Could you please take a look and maybe apply it?

Thanks,
Chris

#1035375#29
Date:
2025-08-03 21:20:02 UTC
From:
To:
Hi,

I had a look at it, and the whole thing is rather confusing. Discussion
text seems to be about SOURCE_DATE_EPOCH, but the only patch contained
here does something else, i.e. changing how the datetime is stored on
the FAT filesystem.

Currently, mtools matches Windows' behavior:

https://stackoverflow.com/questions/38549583/what-time-zone-does-a-fat32-sd-card-record-timestamps-in :

"... The FAT file system records times on disk in local time. ..."

Apparently some digital cameras do store time in UTC though.


As far as SOURCE_DATE_EPOCH is concerned, this is apparently an integer
(seconds since epoch), rather than a structured field showing hour/
minute/seconds, so timezone considerations should not really apply.

Regards,

Alain