Skip to content

[WEBP] Creating lossy webp from this png produces corrupted webp file #2920

Description

@mikethea1

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.8

Other ImageSharp packages and versions

n/a

Environment (Operating system, version and so on)

Windows 11 x64, also reproduced on Amazon Linux x64

.NET Framework version

8

Description

When this .png file is converted to .webp using ImageSharp, it produces a corrupted webp image:

Screenshot of corrupted webp file as viewed in chrome:

Image

I did look at #2068 which seemed like a similar issue but the problem ended up being their environment. In my case, I'm able to reproduce with a minimal reproduction as shown below. I won't rule out that I'm doing something wrong, but I'm not seeing anything and my webp conversion code works beautifully otherwise.

EDIT: I think this is caused by the image having dimensions greater than the max webp supports (16383). So the issue might be more one of argument validation/throwing a clear error message rather than a flaw in the encoding algorithm.

Steps to Reproduce

Repro code:

var path = @"path\to\repro.png";
using var image = SixLabors.ImageSharp.Image.Load(path);
using var outputStream = File.OpenWrite(path + ".webp");
image.Save(outputStream, new WebpEncoder { Quality = 75, Method = WebpEncodingMethod.Fastest, FileFormat = WebpFileFormatType.Lossy });

Images

Input and output files (had to zip since neither would upload directly):

repro.zip

Activity

  1. JimBobSquarePants commented on May 30, 2025

    @JimBobSquarePants
    Member

    Thanks @mikethea1 for the repro and investigation. Yes, we are missing some validation there. We have it in place for lossless encoding only.

  2. mikethea1 commented on Jun 2, 2025

    @mikethea1
    Author

    Thanks for the quick fix @JimBobSquarePants !

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