Repository: minio/minio (language: go)

Issue:
Invalid Bucket creation timestamps "0001-01-01 01:05:21 LMT" in FS Legacy mode
## Expected Behavior
Minio should set valid timestamps for the bucket creation date. For me, all newly created bucket receive the same invalid timestamp `0001-01-01 01:05:21 LMT` which breaks the `awscli ls` with `OverflowError: date value out of range`.

## Current Behavior

I'm sure this is something about my setup, but since a recent update, all buckets that are created on either CLI or Web Interface receive the same invalid timestamp `0001-01-01 01:05:21 LMT`. Buckets that were created before that update have valid timestamps like `2022-08-01 08:39:59 CEST`.


## Steps to Reproduce (for bugs)
```bash
$ mc mb local/test
Bucket created successfully `test`.
$ mc ls local | grep test
[0001-01-01 01:05:21 LMT]     0B test/
```

## Your Environment
```
minio version RELEASE.2022-10-02T19-29-29Z (commit-id=f696a221af84fcff27266fd934a427d346547b93)
Runtime: go1.18.6 linux/amd64
License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
Copyright: 2015-2022 MinIO, Inc.
```



Discussion / hints:
@silverwind I don't see it locally 

```
~ mc mb myminio/test/
Bucket created successfully `myminio/test/`.

~ mc ls myminio/
[2022-10-05 01:16:13 PDT]     0B test/
```

what do the server logs say? 
I run minio via docker and those `stdout` logs are not very verbose. Will try to get more detail logs. I assume the issue must happen during the `s3.putBucket` operation.

<img width="1193" alt="image" src="https://user-images.githubusercontent.com/115237/194019772-03af65c8-893a-46cf-a9a1-7b3e2daa9990.png">

I run minio within a docker container. Date functions do seem to work normally inside the container:

```
[root@1f3e72b97411 /]# date
Wed Oct  5 08:56:00 UTC 2022
```

@silverwind can you do 'ls -ld /path/to/bucket' inside your container ?
Looks normal:

```
[root@1f3e72b97411 /]# ls -ld /data/test
drwxr-xr-x 2 root root 4096 Oct  5 11:38 /data/test
[root@1f3e72b97411 /]# stat /data/test
  File: /data/test
  Size: 4096      	Blocks: 8          IO Block: 4096   directory
Device: fd00h/64768d	Inode: 1704105     Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-10-05 11:38:28.937969204 +0000
Modify: 2022-10-05 11:38:28.937969204 +0000
Change: 2022-10-05 11:38:28.937969204 +0000
 Birth: 2022-10-05 11:38:28.937969204 +0000
```

The  invalid date is only present in the metadata file, but I'm not sure how to decode that format:

```
[root@1f3e72b97411 /]# cat /data/.minio.sys/buckets/test/.metadata.bin | hexdump -C
00000000  01 00 01 00 de 00 15 a4  4e 61 6d 65 a4 74 65 73  |........Name.tes|
00000010  74 a7 43 72 65 61 74 65  64 c7 0c 05 ff ff ff f1  |t.Created.......|
00000020  88 6e 09 00 00 00 00 00  ab 4c 6f 63 6b 45 6e 61  |.n.......LockEna|
00000030  62 6c 65 64 c2 b0 50 6f  6c 69 63 79 43 6f 6e 66  |bled..PolicyConf|
00000040  69 67 4a 53 4f 4e c4 00  b5 4e 6f 74 69 66 69 63  |igJSON...Notific|
00000050  61 74 69 6f 6e 43 6f 6e  66 69 67 58 4d 4c c4 00  |ationConfigXML..|
00000060  b2 4c 69 66 65 63 79 63  6c 65 43 6f 6e 66 69 67  |.LifecycleConfig|
00000070  58 4d 4c c4 00 b3 4f 62  6a 65 63 74 4c 6f 63 6b  |XML...ObjectLock|
00000080  43 6f 6e 66 69 67 58 4d  4c c4 00 b3 56 65 72 73  |ConfigXML...Vers|
00000090  69 6f 6e 69 6e 67 43 6f  6e 66 69 67 58 4d 4c c4  |ioningConfigXML.|
000000a0  00 b3 45 6e 63 72 79 70  74 69 6f 6e 43 6f 6e 66  |..EncryptionConf|
000000b0  69 67 58 4d 4c c4 00 b0  54 61 67 67 69 6e 67 43  |igXML...TaggingC|
000000c0  6f 6e 66 69 67 58 4d 4c  c4 00 af 51 75 6f 74 61  |onfigXML...Quota|
000000d0  43 6f 6e 66 69 67 4a 53  4f 4e c4 00 b4 52 65 70  |ConfigJSON...Rep|
000000e0  6c 69 63 61 74 69 6f 6e  43 6f 6e 66 69 67 58 4d  |licationConfigXM|
000000f0  4c c4 00 b7 42 75 63 6b  65 74 54 61 72 67 65 74  |L...BucketTarget|
00000100  73 43 6f 6e 66 69 67 4a  53 4f 4e c4 00 bb 42 75  |sConfigJSON...Bu|
00000110  63 6b 65 74 54 61 72 67  65 74 73 43 6f 6e 66 69  |cketTargetsConfi|
00000120  67 4d 65 74 61 4a 53 4f  4e c4 00 b5 50 6f 6c 69  |gMetaJSON...Poli|
00000130  63 79 43 6f 6e 66 69 67  55 70 64 61 74 65 64 41  |cyConfigUpdatedA|
00000140  74 c7 0c 05 ff ff ff f1  88 6e 09 00 00 00 00 00  |t........n......|
00000150  b9 4f 62 6a 65 63 74 4c  6f 63 6b 43 6f 6e 66 69  |.ObjectLockConfi|
00000160  67 55 70 64 61 74 65 64  41 74 c7 0c 05 ff ff ff  |gUpdatedAt......|
00000170  f1 88 6e 09 00 00 00 00  00 b9 45 6e 63 72 79 70  |..n.......Encryp|
00000180  74 69 6f 6e 43 6f 6e 66  69 67 55 70 64 61 74 65  |tionConfigUpdate|
00000190  64 41 74 c7 0c 05 ff ff  ff f1 88 6e 09 00 00 00  |dAt........n....|
000001a0  00 00 b6 54 61 67 67 69  6e 67 43 6f 6e 66 69 67  |...TaggingConfig|
000001b0  55 70 64 61 74 65 64 41  74 c7 0c 05 ff ff ff f1  |UpdatedAt.......|
000001c0  88 6e 09 00 00 00 00 00  b4 51 75 6f 74 61 43 6f  |.n.......QuotaCo|
000001d0  6e 66 69 67 55 70 64 61  74 65 64 41 74 c7 0c 05  |nfigUpdatedAt...|
000001e0  ff ff ff f1 88 6e 09 00  00 00 00 00 ba 52 65 70  |.....n.......Rep|
000001f0  6c 69 63 61 74 69 6f 6e  43 6f 6e 66 69 67 55 70  |licationConfigUp|
00000200  64 61 74 65 64 41 74 c7  0c 05 ff ff ff f1 88 6e  |datedAt........n|
00000210  09 00 00 00 00 00 b9 56  65 72 73 69 6f 6e 69 6e  |.......Versionin|
00000220  67 43 6f 6e 66 69 67 55  70 64 61 74 65 64 41 74  |gConfigUpdatedAt|
00000230  c7 0c 05 ff ff ff f1 88  6e 09 00 00 00 00 00     |........n......|
0000023f
````

Also, here's the (sanitized) trace log of the creation, nothing unusual as far as I can see:

````
127.0.0.1:9000  [OS os.Access] [2022-10-05T13:38:28.944] /data/.minio.sys/tmp/f074e3eb-44f0-4283-b625-0619f956f0eb 18.408µs
127.0.0.1:9000  [OS os.Access] [2022-10-05T13:38:28.944] /data/.minio.sys/buckets/test 18.521µs
127.0.0.1:9000  [OS os.Access] [2022-10-05T13:38:28.944] /data/.minio.sys/buckets 12.781µs
127.0.0.1:9000  [OS os.Mkdir] [2022-10-05T13:38:28.944] /data/.minio.sys/buckets/test 112.013µs
127.0.0.1:9000  [OS os.Rename] [2022-10-05T13:38:28.944] /data/.minio.sys/tmp/f074e3eb-44f0-4283-b625-0619f956f0eb/23014458-13f4-41d6-89d4-14ca5655f64d -> /data/.minio.sys/buckets/test/.metadata.bin 103.606µs
minio.example.com [REQUEST s3.PutBucket] [2022-10-05T13:38:28.943] [Client IP: 1.2.3.4]
minio.example.com PUT /test/
minio.example.com Proto: HTTP/1.1
minio.example.com Host: minio.example.com
minio.example.com Authorization: removed
minio.example.com X-Amz-Content-Sha256: UNSIGNED-PAYLOAD
minio.example.com X-Forwarded-For: 1.2.3.4
minio.example.com X-Forwarded-Host: minio.example.com
minio.example.com X-Forwarded-Proto: https
minio.example.com Content-Length: 0
minio.example.com User-Agent: MinIO (linux; amd64) minio-go/v7.0.36 mc/RELEASE.2022-09-16T09-16-47Z
minio.example.com X-Amz-Date: 20221005T113828Z
minio.example.com
minio.example.com [RESPONSE] [2022-10-05T13:38:28.945] [ Duration 1.803ms  ↑ 128 B  ↓ 0 B ]
minio.example.com 200 OK
minio.example.com Strict-Transport-Security: max-age=31536000; includeSubDomains
minio.example.com Vary: Origin,Accept-Encoding
minio.example.com X-Content-Type-Options: nosniff
minio.example.com Server: MinIO
minio.example.com Content-Length: 0
minio.example.com Content-Security-Policy: block-all-mixed-content
minio.example.com Location: /test
minio.example.com X-Amz-Request-Id: 171B294F904B752E
minio.example.com X-Xss-Protection: 1; mode=block
minio.example.com Accept-Ranges: bytes
minio.example.com
minio.example.com
````
Can you attach .metadata.bin file ? 
[Here it is](https://github.com/minio/minio/files/9719508/meta.zip).

Meanwhile, I tried to decode the binary date `c70c05fffffff1886e090000000000`, but it does not make any sense. The binary encoding of these 15 bytes is done [here](https://github.com/tinylib/msgp/blob/f3635b96e4838a6c773babb65ef35297fe5fe2f9/msgp/write_bytes.go#L303).

This is on the `minio/latest` docker tag. Downgrading to  `minio/minio:RELEASE.2021-08-25T00-41-18Z.hotfix.8e9fdf5af` does fix the issue, but I will try more recent releases to see if I can narrow it down further.
I can't seem to reproduce this with any releases we have unit and functional tests to capture this.

Unless the time obtaining itself is broken on your setup I am not sure what it might be.
I can narrow it down to `RELEASE.2022-07-26T00-53-03Z` which is the first bad version that causes it. `RELEASE.2022-07-24T17-09-31Z` works fine.

Diff: https://github.com/minio/minio/compare/RELEASE.2022-07-24T17-09-31Z...RELEASE.2022-07-26T00-53-03Z
Suspected commit: https://github.com/minio/minio/commit/426c902b87d5259f766c20d616811f6d24cc26dd#diff-bcb4657c855306802e845d369b3c56e0f30ddae398f333fa8e7aab3a92fd43bf

And no, I'm not running a cluster, just a single node.
For all I can tell, after https://github.com/minio/minio/commit/426c902b87d5259f766c20d616811f6d24cc26dd, `newBucketMetadata` no longer sets `bucket.Created` to `UTCNow()` so it should end up at the zero value after the function returns, to be updated via `SetCreatedAt`. There are 11 call sites to `newBucketMetadata` in the code base and only two of them call `SetCreatedAt` after `newBucketMetadata`.

Maybe @poornas has some insights.
@silverwind can you cat `/backend_disk/.minio.sys/format.json`? 
Found the problem it is to do with legacy FS backend @silverwind looks like you have an existing setup on this path. 
SetCreatedAt must be called "3" times it was only called 2 times. 

Fix patch:
diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go
index aad24cc79efae..2b7e7e2a50af6 100644
--- a/cmd/fs-v1.go
+++ b/cmd/fs-v1.go
@@ -473,6 +473,7 @@ func (fs *FSObjects) MakeBucketWithLocation(ctx context.Context, bucket string,
 	}
 
 	meta := newBucketMetadata(bucket)
+	meta.SetCreatedAt(opts.CreatedAt)
 	if err := meta.Save(ctx, fs); err != nil {
 		return toObjectErr(err, bucket)
 	}


Test patch: