Skip to content

Exception SixLabors.ImageSharp.ImageFormatException: 'reserved bytes should be zero' when using Image.LoadAsync  #2692

Description

@gieniowski

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

3.1.3

Other ImageSharp packages and versions

Environment (Operating system, version and so on)

Windows 11 with latest updates

.NET Framework version

net8.0.2

Description

I am upgrading version from 3.0.2. Apparently I have an issue when loading image previously created from a particular .jpeg file. Find out the code that reproduces issue below:

using SixLabors.ImageSharp;

await using var pictureStream = File.OpenRead("dwizwcyf.jpeg");

var image = await Image.LoadAsync(pictureStream);

using (var writeStream = File.OpenWrite("result.webp"))
{
    await image.SaveAsWebpAsync(writeStream);
}

var image2 = await Image.LoadAsync("result.webp");

Image.LoadAsync("result.webp") throws this exception SixLabors.ImageSharp.ImageFormatException: 'reserved bytes should be zero'

NOTE: in fact it does not happen in release mode, just debug. I had to mark the checkbox though to create issue. Feel free to ignore it if you find the issue not valuable.

Steps to Reproduce

Open attached jpeg file with imagesharp
Save it as webp
Try to open new webp file again with imagesharp

Images

dwizwcyf

Activity

  1. gieniowski commented on Apr 19, 2024

    @gieniowski
    Author

    @JimBobSquarePants I did the update to the v3.1.4 and I experience the same behavior. Could you reopen the issue please?

  2. hey-red commented on Apr 24, 2024

    @hey-red
    Contributor

    Same issue with v3.1.4.
    But I had same behavior both on debug and release mode.

    file.zip

  3. JimBobSquarePants commented on Apr 24, 2024

    @JimBobSquarePants
    Member

    @hey-red was that file encoded using v3.1.4?

    @gieniowski I cannot replicate your issue with the image and code provided with v3.1.4.

    WebP files encoded using >= 3.1.0 and < v3.1.4 versions will still trigger an error because the encoder wrote over the reserved bytes.

  4. hey-red commented on Apr 24, 2024

    @hey-red
    Contributor

    @JimBobSquarePants Oh, sorry, no. I think this file was taken somewhere from web.
    I got same exception "'reserved bytes should be zero'" while loading
    using Image image = Image.Load(@"C:\file.webp");

    However in browsers/paint.net I can view file without any issues.

  5. JimBobSquarePants commented on Apr 24, 2024

    @JimBobSquarePants
    Member

    I could get rid of the exception; it is a violation of the specification but harmless enough.

  6. hey-red commented on Apr 24, 2024

    @hey-red
    Contributor

    @JimBobSquarePants I'm not sure if this is the correct line, but it seems that libwebp is simply skip these reserved bytes without error.
    https://github.com/webmproject/libwebp/blob/main/src/demux/demux.c#L556

  7. JimBobSquarePants commented on Apr 24, 2024

    @JimBobSquarePants
    Member

    Yeah. That's the animated decoder (don't ask why they split everything out). They do the same in the standard one by reading the uint instead of each byte.

    https://github.com/webmproject/libwebp/blob/3cada4cef46e1ad2ba47a801ac453af95936dfdb/src/dec/webp_dec.c#L124

    I don't know when I'll get round to it personally but if someone wants to PR against the release/v3.1.x branch I'll accept it.

  8. added a commit that references this issue on Jul 10, 2024
    ede33dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions