moby--moby/pkg/archive
Derek Ch b48f4bf523 fix a race crash when building with "ADD some-broken.tar.xz ..."
The race is between pools.Put which calls buf.Reset and exec.Cmd
doing io.Copy from the buffer; it caused a runtime crash, as
described in #16924:

``` docker-daemon cat the-tarball.xz | xz -d -c -q | docker-untar /path/to/... (aufs ) ```

When docker-untar side fails (like try to set xattr on aufs, or a broken
tar), invokeUnpack will be responsible to exhaust all input, otherwise
`xz` will be write pending for ever.

this change add a receive only channel to cmdStream, and will close it
to notify it's now safe to close the input stream;

in CmdStream the change to use Stdin / Stdout / Stderr keeps the
code simple, os/exec.Cmd will spawn goroutines and call io.Copy automatically.

the CmdStream is actually called in the same file only, change it
lowercase to mark as private.

[...]
INFO[0000] Docker daemon                                 commit=0a8c2e3 execdriver=native-0.2 graphdriver=aufs version=1.8.2

DEBU[0006] Calling POST /build
INFO[0006] POST /v1.20/build?cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=gentoo-x32&ulimits=null
DEBU[0008] [BUILDER] Cache miss
DEBU[0009] Couldn't untar /home/lib-docker-v1.8.2-tmp/tmp/docker-build316710953/stage3-x32-20151004.tar.xz to /home/lib-docker-v1.8.2-tmp/aufs/mnt/d909abb87150463939c13e8a349b889a72d9b14f0cfcab42a8711979be285537: Untar re-exec error: exit status 1: output: operation not supported
DEBU[0009] CopyFileWithTar(/home/lib-docker-v1.8.2-tmp/tmp/docker-build316710953/stage3-x32-20151004.tar.xz, /home/lib-docker-v1.8.2-tmp/aufs/mnt/d909abb87150463939c13e8a349b889a72d9b14f0cfcab42a8711979be285537/)
panic: runtime error: slice bounds out of range

goroutine 42 [running]:
bufio.(*Reader).fill(0xc208187800)
    /usr/local/go/src/bufio/bufio.go:86 +0x2db
bufio.(*Reader).WriteTo(0xc208187800, 0x7ff39602d150, 0xc2083f11a0, 0x508000, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:449 +0x27e
io.Copy(0x7ff39602d150, 0xc2083f11a0, 0x7ff3960261f8, 0xc208187800, 0x0, 0x0, 0x0)
    /usr/local/go/src/io/io.go:354 +0xb2
github.com/docker/docker/pkg/archive.func·006()
    /go/src/github.com/docker/docker/pkg/archive/archive.go:817 +0x71
created by github.com/docker/docker/pkg/archive.CmdStream
    /go/src/github.com/docker/docker/pkg/archive/archive.go:819 +0x1ec

goroutine 1 [chan receive]:
main.(*DaemonCli).CmdDaemon(0xc20809da30, 0xc20800a020, 0xd, 0xd, 0x0, 0x0)
    /go/src/github.com/docker/docker/docker/daemon.go:289 +0x1781
reflect.callMethod(0xc208140090, 0xc20828fce0)
    /usr/local/go/src/reflect/value.go:605 +0x179
reflect.methodValueCall(0xc20800a020, 0xd, 0xd, 0x1, 0xc208140090, 0x0, 0x0, 0xc208140090, 0x0, 0x45343f, ...)
    /usr/local/go/src/reflect/asm_amd64.s:29 +0x36
github.com/docker/docker/cli.(*Cli).Run(0xc208129fb0, 0xc20800a010, 0xe, 0xe, 0x0, 0x0)
    /go/src/github.com/docker/docker/cli/cli.go:89 +0x38e
main.main()
    /go/src/github.com/docker/docker/docker/docker.go:69 +0x428

goroutine 5 [syscall]:
os/signal.loop()
    /usr/local/go/src/os/signal/signal_unix.go:21 +0x1f
created by os/signal.init·1
    /usr/local/go/src/os/signal/signal_unix.go:27 +0x35

Signed-off-by: Derek Ch <denc716@gmail.com>
2015-10-13 15:58:06 -07:00
..
testdata Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
README.md Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
archive.go fix a race crash when building with "ADD some-broken.tar.xz ..." 2015-10-13 15:58:06 -07:00
archive_test.go fix a race crash when building with "ADD some-broken.tar.xz ..." 2015-10-13 15:58:06 -07:00
archive_unix.go Add user namespace (mapping) support to the Docker engine 2015-10-09 17:47:37 -04:00
archive_unix_test.go pkg/archive: adjust chmod bits on windows 2015-03-04 14:10:37 -08:00
archive_windows.go Add user namespace (mapping) support to the Docker engine 2015-10-09 17:47:37 -04:00
archive_windows_test.go trivial: typo cleanup 2015-04-27 13:35:08 -07:00
changes.go Add user namespace (mapping) support to the Docker engine 2015-10-09 17:47:37 -04:00
changes_linux.go ino and dev must both match for a file to be identical. 2015-05-05 11:06:54 -04:00
changes_other.go Windows: Docker build starting to work 2015-06-17 10:41:28 -07:00
changes_posix_test.go Add user namespace (mapping) support to the Docker engine 2015-10-09 17:47:37 -04:00
changes_test.go Add user namespace (mapping) support to the Docker engine 2015-10-09 17:47:37 -04:00
changes_unix.go Correct mismatched function names (UID() and Gid()) 2015-10-12 10:58:33 -04:00
changes_windows.go fix golint warnings/errors on `pkg/system` and `pkg/stdcopy` 2015-08-13 18:47:13 +08:00
copy.go Windows: Fix absolute checks 2015-09-01 08:41:37 -07:00
copy_test.go Fix `docker cp` Behavior With Symlinks 2015-07-30 12:14:28 -07:00
copy_unix.go Windows - make docker cp functional 2015-08-06 11:22:38 -07:00
copy_windows.go Windows - make docker cp functional 2015-08-06 11:22:38 -07:00
diff.go Windows: Fix AV in build due to userns 2015-10-13 14:02:25 -07:00
diff_test.go Finally remove our copy of "archive/tar" now that Go 1.4 is the minimum! 2015-05-01 16:01:10 -06:00
example_changes.go archive: example app for diffing directories 2014-10-29 14:52:59 -04:00
time_linux.go Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
time_unsupported.go Move archive package into pkg/archive 2014-09-29 23:23:36 -07:00
utils_test.go Enable golint in pkg/arcive 2015-08-04 09:52:54 +08:00
whiteouts.go Add constants for AUFS whiteout files 2015-09-29 11:21:45 -07:00
wrap.go Finally remove our copy of "archive/tar" now that Go 1.4 is the minimum! 2015-05-01 16:01:10 -06:00
wrap_test.go Add coverage on pkg/archive 2015-04-24 17:03:33 +02:00

README.md

This code provides helper functions for dealing with archive files.