Skip to content

System.NullReferenceException when resizing jpeg file #2056

Closed

Description

@hey-red

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

2.0

Other ImageSharp packages and versions

SixLabors.ImageSharp.Web 2.0.0-alpha.0.19

Environment (Operating system, version and so on)

Windows 10, Ubuntu 20.04

.NET Framework version

NET 6

Description

I got an System.NullReferenceException when trying to resize jpeg file.

Here is stacktrace:

System.NullReferenceException
   at SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifValue..ctor(ExifValue other)
   at SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifArrayValue`1..ctor(ExifArrayValue`1 value)
   at SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifRationalArray..ctor(ExifRationalArray value)
   at SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifRationalArray.DeepClone()
   at SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifProfile..ctor(ExifProfile other)
   at SixLabors.ImageSharp.Metadata.ImageMetadata..ctor(ImageMetadata other)
   at SixLabors.ImageSharp.Processing.Processors.CloningImageProcessor`1.CreateTarget()
   at SixLabors.ImageSharp.Processing.Processors.CloningImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.ICloningImageProcessor<TPixel>.CloneAndExecute()
   at SixLabors.ImageSharp.Processing.Processors.CloningImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.IImageProcessor<TPixel>.Execute()
   at SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
   at SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, ResizeOptions options)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, Int32 width, Int32 height, IResampler sampler, Rectangle targetRectangle, Boolean compand)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, Int32 width, Int32 height, IResampler sampler, Boolean compand)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, Int32 width, Int32 height)
   at Program.<>c__DisplayClass0_0.<<Main>$>b__0(IImageProcessingContext x)

ImageMagick identify:

Image:
  Filename: .\sample.jpeg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 2000x1125+0+0
  Units: Undefined
  Colorspace: sRGB
  Type: TrueColor
  Base type: Undefined
  Endianness: Undefined
  Depth: 8-bit
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 2250000
    Red:
      min: 0  (0)
      max: 255 (1)
      mean: 53.5981 (0.210189)
      median: 35 (0.137255)
      standard deviation: 40.1592 (0.157487)
      kurtosis: 8.31938
      skewness: 2.71307
      entropy: 0.788198
    Green:
      min: 0  (0)
      max: 255 (1)
      mean: 31.9105 (0.125139)
      median: 14 (0.054902)
      standard deviation: 36.6292 (0.143644)
      kurtosis: 11.1506
      skewness: 3.07986
      entropy: 0.708739
    Blue:
      min: 0  (0)
      max: 255 (1)
      mean: 36.9177 (0.144775)
      median: 18 (0.0705882)
      standard deviation: 33.7425 (0.132323)
      kurtosis: 7.88462
      skewness: 2.48392
      entropy: 0.765609
  Image statistics:
    Overall:
      min: 0  (0)
      max: 255 (1)
      mean: 40.8088 (0.160034)
      median: 22.3333 (0.0875817)
      standard deviation: 36.8436 (0.144485)
      kurtosis: 8.64769
      skewness: 2.635
      entropy: 0.754182
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 2000x1125+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 80
  Orientation: Undefined
  Profiles:
    Profile-exif: 8419 bytes
  Properties:
    date:create: 2022-03-09T19:43:32+00:00
    date:modify: 2022-03-09T19:43:32+00:00
    exif:ExifOffset: 86
    exif:ExifVersion: 48, 50, 50, 48
    exif:ImageLength: 2160
    exif:ImageWidth: 3840
    exif:InterColorProfile: 0, 0, 12, 72, 76, 105, 110, 111, 2, 16, 0, 0, 109, 110, 116, 114, 82, 71, 66, 32, 88, 89, 90, 32, 7, 206, 0, 2, 0, 9, 0, 6, 0, 49, 0, 0, 97, 99, 115, 112, 77, 83, 70, 84, 0, 0, 0, 0, 73, 69, 67, 32, 115, 82, 71, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 246, 214, 0, 1, 0, 0, 0, 0, 211, 45, 72, 80, 32, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 99, 112, 114, 116, 0, 0, 1, 80, 0, 0, 0, 51, 100, 101, 115, 99, 0, 0, 1, 132, 0, 0, 0, 108, 119, 116, 112, 116, 0, 0, 1, 240, 0, 0, 0, 20, 98, 107, 112, 116, 0, 0, 2, 4, 0, 0, 0, 20, 114, 88, 89, 90, 0, 0, 2, 24, 0, 0, 0, 20, 103, 88, 89, 90, 0, 0, 2, 44, 0, 0, 0, 20, 98, 88, 89, 90, 0, 0, 2, 64, 0, 0, 0, 20, 100, 109, 110, 100, 0, 0, 2, 84, 0, 0, 0, 112, 100, 109, 100, 100, 0, 0, 2, 196, 0, 0, 0, 136, 118, 117, 101, 100, 0, 0, 3, 76, 0, 0, 0, 134, 118, 105, 101, 119, 0, 0, 3, 212, 0, 0, 0, 36, 108, 117, 109, 105, 0, 0, 3, 248, 0, 0, 0, 20, 109, 101, 97, 115, 0, 0, 4, 12, 0, 0, 0, 36, 116, 101, 99, 104, 0, 0, 4, 48, 0, 0, 0, 12, 114, 84, 82, 67, 0, 0, 4, 60, 0, 0, 8, 12, 103, 84, 82, 67, 0, 0, 4, 60, 0, 0, 8, 12, 98, 84, 82, 67, 0, 0, 4, 60, 0, 0, 8, 12, 116, 101, 120, 116, 0, 0, 0, 0, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 40, 99, 41, 32, 49, 57, 57, 56, 32, 72, 101, 119, 108, 101, 116, 116, 45, 80, 97, 99, 107, 97, 114, 100, 32, 67, 111, 109, 112, 97, 110, 121, 0, 0, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 18, 115, 82, 71, 66, 32, 73, 69, 67, 54, 49, 57, 54, 54, 45, 50, 46, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 115, 82, 71, 66, 32, 73, 69, 67, 54, 49, 57, 54, 54, 45, 50, 46, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 243, 81, 0, 1, 0, 0, 0, 1, 22, 204, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 111, 162, 0, 0, 56, 245, 0, 0, 3, 144, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 98, 153, 0, 0, 183, 133, 0, 0, 24, 218, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 36, 160, 0, 0, 15, 132, 0, 0, 182, 207, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 22, 73, 69, 67, 32, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 105, 101, 99, 46, 99, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 73, 69, 67, 32, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 105, 101, 99, 46, 99, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 46, 73, 69, 67, 32, 54, 49, 57, 54, 54, 45, 50, 46, 49, 32, 68, 101, 102, 97, 117, 108, 116, 32, 82, 71, 66, 32, 99, 111, 108, 111, 117, 114, 32, 115, 112, 97, 99, 101, 32, 45, 32, 115, 82, 71, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 73, 69, 67, 32, 54, 49, 57, 54, 54, 45, 50, 46, 49, 32, 68, 101, 102, 97, 117, 108, 116, 32, 82, 71, 66, 32, 99, 111, 108, 111, 117, 114, 32, 115, 112, 97, 99, 101, 32, 45, 32, 115, 82, 71, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 101, 115, 99, 0, 0, 0, 0, 0, 0, 0, 44, 82, 101, 102, 101, 114, 101, 110, 99, 101, 32, 86, 105, 101, 119, 105, 110, 103, 32, 67, 111, 110, 100, 105, 116, 105, 111, 110, 32, 105, 110, 32, 73, 69, 67, 54, 49, 57, 54, 54, 45, 50, 46, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 82, 101, 102, 101, 114, 101, 110, 99, 101, 32, 86, 105, 101, 119, 105, 110, 103, 32, 67, 111, 110, 100, 105, 116, 105, 111, 110, 32, 105, 110, 32, 73, 69, 67, 54, 49, 57, 54, 54, 45, 50, 46, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, 105, 101, 119, 0, 0, 0, 0, 0, 19, 164, 254, 0, 20, 95, 46, 0, 16, 207, 20, 0, 3, 237, 204, 0, 4, 19, 11, 0, 3, 92, 158, 0, 0, 0, 1, 88, 89, 90, 32, 0, 0, 0, 0, 0, 76, 9, 86, 0, 80, 0, 0, 0, 87, 31, 231, 109, 101, 97, 115, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 143, 0, 0, 0, 2, 115, 105, 103, 32, 0, 0, 0, 0, 67, 82, 84, 32, 99, 117, 114, 118, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 5, 2
    exif:PixelXDimension: 2000
    exif:PixelYDimension: 1125
    exif:Software: PaintShop Pro 21,00
    exif:thumbnail:Compression: 6
    exif:thumbnail:JPEGInterchangeFormat: 3406
    exif:thumbnail:JPEGInterchangeFormatLength: 5007
    exif:thumbnail:ResolutionUnit: 2
    exif:thumbnail:XResolution: 72/1
    exif:thumbnail:YResolution: 72/1
    exif:YCbCrCoefficients:
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x2,1x1,1x1
    signature: fecaa760ccb6348b9ce350b479bdc61bd899d5559acea575cd67a79d3b2de7b6
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 250451B
  Number pixels: 2250000
  Pixels per second: 95.7255MP
  User time: 0.016u
  Elapsed time: 0:01.023
  Version: ImageMagick 7.1.0-27 Q16-HDRI x64 2022-03-05 https://imagemagick.org

Steps to Reproduce

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;

using (Image image = Image.Load("sample.jpeg"))
{
    image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
}

Images

sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions