buildah icon indicating copy to clipboard operation
buildah copied to clipboard

error parsing last-modified time when using ADD command

Open libinglong opened this issue 2 years ago • 5 comments

Description

Steps to reproduce the issue:

  1. ADD http://xxx /anywhere in Dockerfile
  2. the http://xxx has header "Last-Modified: Mon, 5 Dec 2022 02:52:24 GMT"
  3. buildah built -t anytag --layers=true --pull=false .

Describe the results you received: error building at STEP "ADD http://xxx /anywhere": error reading "http://xxx": error parsing last-modified time: parsing time "Mon, 5 Dec 2022 02:52:24 GMT" as "Mon, 02 Jan 2006 15:04:05 MST": cannot parse "5 Dec 2022 02:52:24 GMT" as "02"

Describe the results you expected: No error

Output of rpm -q buildah or apt list buildah:

# apt list buildah
Listing... Done
buildah/jammy,now 1.23.1+ds1-2 amd64 [installed]

Output of buildah version:

# buildah -v
buildah version 1.23.1 (image-spec 1.0.1, runtime-spec 1.0.2-dev)

Output of cat /etc/*release:

root@744ad4f05012:/# cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Output of uname -a:

root@744ad4f05012:/# uname -a
Linux 744ad4f05012 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of cat /etc/containers/storage.conf:

root@744ad4f05012:/# cat /etc/containers/storage.conf
cat: /etc/containers/storage.conf: No such file or directory

libinglong avatar Dec 28 '22 03:12 libinglong

image

image

It seems the http respone last-modified time does not exactly match rfc1123 time pattern.

libinglong avatar Dec 28 '22 04:12 libinglong

My url is a S3 object of which respone header does not padding a zero when the date is a single number.

libinglong avatar Dec 28 '22 06:12 libinglong

Any idea on how to fix this?

rhatdan avatar Dec 29 '22 15:12 rhatdan

Hi @libinglong , I think for GMT we need to provide a custom layout as, could you try the below diff and tell me if it works

diff --git a/add.go b/add.go
index 1bb6c850..a47df02d 100644
--- a/add.go
+++ b/add.go
@@ -102,7 +102,12 @@ func getURL(src string, chown *idtools.IDPair, mountpoint, renameTarget string,
        date := time.Unix(0, 0).UTC()
        lastModified := response.Header.Get("Last-Modified")
        if lastModified != "" {
-               d, err := time.Parse(time.RFC1123, lastModified)
+               layout := time.RFC1123
+               if strings.HasSuffix(lastModified, "GMT") {
+                       lastModified = lastModified + "+00+0000"
+                       layout = "Mon, 02 Jan 2006 15:04:05 MST-0700"
+               }
+               d, err := time.Parse(layout, lastModified)
                if err != nil {
                        return fmt.Errorf("parsing last-modified time: %w", err)
                }

There is a issue when GMT iS passed in, i was able to reproduce it in a new go file below.

package main

import (
	"fmt"
	"time"
)

func main() {
	d, err := time.Parse("Mon, 02 Jan 2006 15:04:05 MST-0700", "Mon, 05 Dec 2022 02:52:24 GMT+00+0000")
	if err != nil {
		fmt.Printf("parsing last-modified time: %+v", err)
	}
	fmt.Printf("----%+v\n", d)
}

flouthoc avatar Dec 29 '22 16:12 flouthoc

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Jan 29 '23 00:01 github-actions[bot]