Repository: dotnet/dotnet-docker

Issue #1465: Cannot create Bitmap from stream inside Alpine-based dotnet image
Created: 2019-11-14T08:35:58Z
Steps to reproduce the issue

Clone https://github.com/framebassman/BlobContentType repository
git clone git@github.com:FrameBassman/BlobContentType.git
Run application
make start-test
Make sure the app is running
bash ./Scripts/wait-until-service-is-up.sh
Run test
dotnet test BlobContentType.Test

Expected behavior
Application should not throw an exception. Test should pass
Actual behavior
Test fails. The following code:
var imageUrl = "https://barcode.tec-it.com/barcode.ashx?data=ABC-abc-1234&code=Code128&dpi=96";
using(var input = await _client.GetStreamAsync(imageUrl)) 
{
 _log.LogWarning("Inside input");
 using(var memory = new MemoryStream())
 {
  _log.LogWarning("Inside memory");
  var bitmap = new Bitmap(input);
 }
}

throws the following exception
warn: BlobContentType.Web.Controllers.PictureController[0]
      Inside input
warn: BlobContentType.Web.Controllers.PictureController[0]
      Inside memory
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLR8REHR5AL4", Request id "0HLR8REHR5AL4:00000001": An unhandled exception was thrown by the application.
System.ArgumentException: Parameter is not valid.
   at System.Drawing.Image.InitializeFromStream(Stream stream)
   at System.Drawing.Bitmap..ctor(Stream stream)
   at BlobContentType.Web.Controllers.PictureController.Index() in /app/Controllers/PictureController.cs:line 34
...

Additional information (e.g. issue happens only occasionally)
I have install the following libraries inside alpine-based container
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
    && apk update \
    && apk add \
        libgdiplus

Output of docker version
Client: Docker Engine - Community
 Version:           19.03.4
 API version:       1.40
 Go version:        go1.12.10
 Git commit:        9013bf583a
 Built:             Fri Oct 18 15:54:09 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.4
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.10
  Git commit:       9013bf583a
  Built:            Fri Oct 18 15:52:40 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683


Output of docker info
Client:
 Debug Mode: false

Server:
 Containers: 2
  Running: 2
  Paused: 0
  Stopped: 0
 Images: 292
 Server Version: 19.03.4
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.0.0-35-generic
 Operating System: Ubuntu 18.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.28GiB
 Name: cs-ws174380
 ID: JROJ:UOIZ:XFEN:V26K:IA6A:IKXG:XVRZ:T2AZ:MN2N:IXAJ:SYRN:6KC6
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: framebassman
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support

Duplicate issue #1541: Image.FromStream throws ArgumentException in Alpine based docker image when trying to load gif
Created: 2019-12-30T07:21:12Z
Steps to reproduce the issue

Create asp net core project.
Use command System.Drawing.Image.FromStream("/app/Images/1.gif")
Use base image mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine
Use additional libs:

apk add libgdiplus --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
apk add --no-cache libgcc icu-dev libc6-compat icu-libs giflib

Use microsoft/dotnet:2.2-sdk to build project

Expected behavior
Image is loading correctly without exception
Actual behavior
System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.InitializeFromStream(Stream stream)
at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive)
at TestGdiDotnet2.TryLoadImages.DoProduce(Object state) in /src/TestGdiDotnet2/TryLoadImages.cs:line 55
Additional information (e.g. issue happens only occasionally)
The problem is in Alpine based image only. When I use microsoft/dotnet:2.2-aspnetcore-runtime the same file is loaded correctly.
Output of docker version
Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Output of docker info
Containers: 3
 Running: 1
 Paused: 0
 Stopped: 2
Images: 562
Server Version: 18.09.2
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 8.003GiB
Name: linuxkit-00155d8071b9
ID: M5ML:GEYK:HHTS:P3B4:YWOP:3MQT:Y6YC:CA73:BAQG:DCHE:2YD2:GEOG
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 28
 Goroutines: 51
 System Time: 2019-12-30T07:11:05.1515601Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 nexus2.zyfra.com:8082
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

Closing comment (2019-12-30T15:25:41Z): Duplicate of #1465