Commit Graph

5014 Commits

Author SHA1 Message Date
9769bb767c configure: add -Wself-assign
Bug: 432511225
Change-Id: I4e074909221ac4c0a26613d4441ea00c430bcb94
2025-08-14 12:03:57 -07:00
61e5c391d6 Revert "dsp/lossless{,_enc}_sse2.c: reorder *_SSE assignments"
This reverts commit 2246828be3.

Reason for revert: NULL dereferences in the fuzzers.
The `VP8LPredictorsAdd_SSE` table is not completely initialized (index
14 and 15) which may be accessed with an invalid bitstream.

Bug: 435213378
Original change's description:
> dsp/lossless{,_enc}_sse2.c: reorder *_SSE assignments
>
> When `WEBP_USE_THREAD` is not defined the assignments of *_SSE and their
> unsuffixed counterparts may race. Assigning *_SSE directly rather than
> relying on the unsuffixed values avoids a case where the *_SSE variants
> may refer to the calling function (i.e., AVX2) resulting in infinite
> recursion.
>
> Defining `WEBP_USE_THREAD` is recommended when decode/encode calls can
> be made from different threads.
>
> Bug: 435213378
> Change-Id: Id5549730cb72be99b3014ed8e4e355f3ea988659

Bug: 435213378, 438295348, 438294044, 438264629, 438294033
Change-Id: I3299d6fbb29c45872e2ea1f8f1c3d0ebbda64a69
2025-08-13 17:10:20 -07:00
2246828be3 dsp/lossless{,_enc}_sse2.c: reorder *_SSE assignments
When `WEBP_USE_THREAD` is not defined the assignments of *_SSE and their
unsuffixed counterparts may race. Assigning *_SSE directly rather than
relying on the unsuffixed values avoids a case where the *_SSE variants
may refer to the calling function (i.e., AVX2) resulting in infinite
recursion.

Defining `WEBP_USE_THREAD` is recommended when decode/encode calls can
be made from different threads.

Bug: 435213378
Change-Id: Id5549730cb72be99b3014ed8e4e355f3ea988659
2025-08-07 13:50:16 -07:00
4bcea04803 Merge "Implement pthread_mutex_t using SRWLOCK on Windows" into main 2025-08-06 19:02:21 -07:00
6913049d6e Merge "Fix universal macOS binaries builds" into main 2025-08-06 18:42:19 -07:00
6680723e66 Implement pthread_mutex_t using SRWLOCK on Windows
SRWLOCK is faster than CRITICAL_SECTION. MSVC implements the C11 mtx_t
and C++ std::mutex using SRWLOCK.

Change-Id: I144d2f53aeaa135030ea8c057a2ae8543e6c91b8
2025-08-06 18:27:58 -07:00
0ce96e30e0 Merge "cpu.cmake,cosmetics: apply cmake-format" into main 2025-08-06 16:52:06 -07:00
ac2795e904 Remove pthread code for Windows older than Vista
Assume the CONDITION_VARIABLE added in Windows Vista is available.

Remove an unneeded WaitForSingleObject() macro that converts
WaitForSingleObject() calls to WaitForSingleObjectEx() calls with
bAlertable=FALSE. The WaitForSingleObject() function does not enter an
alertable wait state, so it is equivalent to WaitForSingleObjectEx()
with bAlertable=FALSE.

Remove code for Windows older than Vista in src/dsp/cpu.h.

Change-Id: I7df95557713923e05a7bfb62e095ec6172cfd708
2025-08-05 12:01:55 -07:00
c41d168d25 Merge "Apply "default unsafe" annotation across webputils" into main 2025-08-05 11:23:47 -07:00
019ce505e9 cpu.cmake,cosmetics: apply cmake-format
Change-Id: I16e675beb601c5845723ac9635cfb64f38a70603
2025-08-05 11:22:22 -07:00
e329ca4c26 Fix universal macOS binaries builds
Trying to compile libwebp with CMAKE_OSX_ARCHITECTURES="x86_64;arm64"
(also called as universal binary), will always fail due to SIMD
intrinsics check. CMake passes `-arch x86_64 -arch arm64` into the
compiler during `check_c_source_compiles`, which will always fail for
any flag, because either x86_64 or arm64 won't have it. This also
results in you not being able to compile the library due to errors like
"SSE2 register return with SSE2 disabled".

Change-Id: I32a41e4c64ce8c6a043083023a4018d512be124b
2025-08-05 04:49:43 -07:00
ff87eeecc9 Apply "default unsafe" annotation across webputils
Import bounds_safety.h across all of webputils, with one exception being
dsp.h, since it's imported by webputils.h in one place. Also prepend
WEBP_ASSUME_UNSAFE_INDEXABLE_ABI to every webputil file to indicate to
the compiler that every pointer should be treated as __unsafe_indexable.

We also need to replace memcpy/memset/memmove with the unsafe variants
WEBP_UNSAFE_*, as memcpy/memset/memmove require bounded/sized pointers.

With this change, all of libwebputils (and libwebp) should build with
-DWEBP_ENABLE_FBOUNDS_SAFETY=true

Change-Id: Iad87be0455182d534c074ef6dc1a30fa66b74b6c
2025-08-04 18:56:57 -07:00
b0e8039062 Merge changes Iecff615a,I1237904a into main
* changes:
  Implement WEBP_DSP_INIT with SRWLOCK for Windows
  Use file static variables in WEBP_DSP_INIT_FUNC()
2025-08-04 17:38:04 -07:00
0a6869b1bc Merge "add .clang-format" into main 2025-08-04 16:24:32 -07:00
54f23b049e Implement WEBP_DSP_INIT with SRWLOCK for Windows
A slim reader/writer (SRW) lock can be initialized statically with the
constant SRWLOCK_INIT. It is the only Windows synchronization object I
can find with this property.

Note: On old Windows versions that don't have SRWLOCK, use the fallback,
thread-unsafe implementation.

Change a NOLINT comment to a NOLINTNEXTLINE comment to prevent
clang-format from aligning the #else and #endif comments in undesired
way.

Bug: 435213378
Change-Id: Iecff615a14a1905aedd2c05ad9444889f711cc17
2025-08-04 15:01:09 -07:00
db608edd71 unicode.h: fix include order on windows
shellapi.h must be included after windows.h; fixes:
/Windows Kits/10/Include/10.0.26100.0/um/shellapi.h|68 col 1| error:
unknown type name 'EXTERN_C'

when building using VS 2022 after:
44257cb8 apply clang-format

Bug: 433996651
Change-Id: I8f340cdaf6d6b315f1b7535710847db786599da1
2025-08-04 12:53:40 -07:00
313692d51e Use file static variables in WEBP_DSP_INIT_FUNC()
Function static variables are initialized on the first call to the
function. In C the initialization of function static variables is not
thread-safe. Use file static variables instead in the
WEBP_DSP_INIT_FUNC() macro.

Remove the volatile qualifier for the pthread version of the
func##_last_cpuinfo_used variable because the variable is only accessed
while holding the mutex.

Change-Id: I1237904a49d2467d7ce79fc53f9e7f966aa7a5c1
2025-08-01 19:22:17 -07:00
484991ce3f Merge "Merge the mallocs in sharpyuv." into main 2025-08-01 13:19:45 -07:00
67cd2fc03a add .clang-format
Google style, with no overrides. This may help automatic formatting in
some tools that don't pass `--style` by default.

Bug: 433996651
Change-Id: I5fb28f43bd3dd1862aaf89b73a24dfb63f80a193
2025-08-01 13:14:54 -07:00
0de0a62305 Merge the mallocs in sharpyuv.
Change-Id: I671945fca6bfefd1b7f4e6dda5b068bac9407ad6
2025-07-31 20:54:06 -07:00
f3109bd6c8 CONTRIBUTING.md: update clang-format text
The project now uses `clang-format --style=Google` to format the code.

Bug: 433996651
Change-Id: I3e4dedcb20006ef46692f89c3605d966c4880052
2025-07-31 16:24:39 -07:00
44257cb826 apply clang-format
(Debian clang-format version 19.1.7 (3+build4)) with `--style=Google`.

Manual changes:
* clang-format disabled around macros with stringification (mostly
  assembly)
* some inline assembly strings were adjusted to avoid awkward line
  breaks
* trailing commas, `//` or suffixes (`ull`) added to help array
  formatting
* thread_utils.c: parameter comments were changed to the more common
  /*...=*/ style to improve formatting

The automatically generated code under swig/ was skipped.

Bug: 433996651
Change-Id: Iea3f24160d78d2a2653971cdf13fa932e47ff1b3
2025-07-31 14:53:58 -07:00
b569988d3f Merge "Set best frame candidate at each encode in animenc" into main 2025-07-31 01:33:58 -07:00
5531b1e7b7 Merge changes Ie4e2908b,I54e62206 into main
* changes:
  anim_diff: normalize `ok = ... && ok` statements
  examples/{webpmux,unicode}: simplify W_CHAR casts
2025-07-30 13:54:51 -07:00
b1feaa40b8 Set best frame candidate at each encode in animenc
Rather than encoding all candidates then finding the smallest output,
only keep the frame candidate leading to the shortest bitstream at all
times. Some memory is released slightly sooner when there are more
than two frame candidates.

The simple assignments in PickBestCandidate() are now done for each
new best candidate so far instead of once for the one best overall
candidate, but they are cheap and overwritten. This change should
have no impact on encoded animation files.

Change-Id: Ie540f104a70de7a84535f8f2c49d1a71fa5b4bfa
2025-07-30 12:04:46 +00:00
e721627c25 anim_diff: normalize ok = ... && ok statements
`ok &= ...` is more common in the codebase than `ok = ... && ok` when
accumulating a result while unconditionally executing functions. (`ok =
ok &&` is used in cases that should short circuit.) In this case
multiple checks may fail and their error messages may aid in debugging.

This will also improve the formatting when clang-format is applied to
the codebase.

Bug: 433996651
Change-Id: Ie4e2908b857122d90f6e93f06b10cb48dc86b18e
2025-07-29 20:40:09 -07:00
86924ed5cd examples/{webpmux,unicode}: simplify W_CHAR casts
in calls to `LOCAL_FREE()`: `(W_CHAR** const) -> (W_CHAR**)`. This will
improve formatting when clang-format is applied.

Bug: 433996651
Change-Id: I54e62206c83473e9369b8c67fb8d6c44d7808d52
2025-07-29 19:25:22 -07:00
3a55b076c9 Fix comment in anim_encode for key frame candidate
Change-Id: I12804097a5ea5025cb4a019a247371db761dab66
2025-07-29 13:13:30 +00:00
bfea600a5f Set prev_candidate_undecided in anim_enc
When the next frame is forced to be a keyframe by setting
enc->best_delta to DELTA_INFINITY, setting enc->keyframe to NONE means
the current frame will never be converted from a candidate keyframe to
a subframe. So enc->prev_candidate_undecided should be set to 0.
This is a no-op change because enc->prev_candidate_undecided is only
used to update prev_rect and dispose method, which is of no value when
the next frame is a key frame.

Change-Id: Ie51c7e3b6ba797b75af5e06439e8568d8185693f
2025-07-29 07:48:02 +00:00
ab0a07fcf5 Merge "Create src/utils/bounds_safety.h" into main 2025-07-28 17:28:22 -07:00
9aebd2a64e Create src/utils/bounds_safety.h
The macros in src/utils/bounds_safety.h exist to ensure libwebp
stays portable. This also provides wrappers around common functions like
memcpy/memset/memmove, which are useful as part of the migration. Memcpy
(et al.) wrappers aren't expected to exist forever, and can be removed
after the codebase is fully annotated.

There's some complexity here due to the number of states we need to
support:

1) Off everywhere
2) Building libwebp (some or all) with -fbounds-safety
3) Linking against libwebp that was built with -fbounds-safety
4) Inter-operation with C++

Change-Id: I789f0a94f25b70cab172d5b3f5e6b12de3a34bb4
2025-07-29 00:00:16 +00:00
8c815d82d7 Add ARGB/ABGR support to WebPConvertRGB24ToY/WebPConvertBGR24ToY
Rename them to WebPConvertRGBToY/WebPConvertBGRToY and accept the
'step' parameter (3 for RGB, 4 for ARGB).

Change-Id: I930a23894e4135a34fff2174e6a5bbee1eac2ba0
2025-07-24 14:14:20 +02:00
a81af56db9 src/dec: fix a status reported during setup
If setup() fails, it is not because the user did an abort according
the doc :
https://chromium.googlesource.com/webm/libwebp/+/refs/tags/v1.6.0/src/dec/vp8_dec.h#74

Bug: webp:433456394
Change-Id: I25020304ccdb8eae32134c1400a918e7c4cc0385
2025-07-23 11:08:02 +02:00
4e63ff1eb6 Fix lossy/lossless typo in anim_encode
Change-Id: Iad9e4a6b4731b280bd444a288501b36de16e0268
2025-07-21 13:49:37 +00:00
a7002d2089 Add WEBP_ENABLE_FBOUNDS_SAFETY to CMakeLists.txt
Conditionally enable -fbounds-safety for webputils

This is the first step towards making -fbounds-safety
(https://clang.llvm.org/docs/BoundsSafety.html) available to folks with
a supported toolchain.

In the next CL, I'll provide a header file which wraps the annotations,
keeping the code portable. It will also address the build failures below
by marking the webputils files as "default unsafe", which shouldn't
change any behavior (build or runtime) when -fbounds-safety is disabled.

Example using a toolchain built from github.com/swiftlang/llvm-project/next

```
$ mkdir build && cd build
$ cmake .. -DCMAKE_C_COMPILER=$(pwd)/../llvm-build/bin/clang -DCMAKE_CXX_COMPILER=$(pwd)/../llvm-build/bin/clang++ -DWEBP_ENABLE_FBOUNDS_SAFETY=true
$ make
...
[ 74%] Building C object CMakeFiles/webputils.dir/src/utils/bit_reader_utils.c.o
In file included from libwebp/src/utils/bit_reader_utils.c:23:
In file included from libwebp/src/utils/bit_reader_inl_utils.h:30:
libwebp/src/utils/utils.h:72:14: error: passing 'const uint8_t *__single' (aka 'const unsigned char *__single') with pointee of size 1 to parameter '__src' of type
      'const void *__single __sized_by(__n)' (aka 'const void *__single') with size value of 4 always fails
   72 |   memcpy(&A, ptr, sizeof(A));
      |              ^    ~~~~~~~~~
...
```

Bug: webp:432511821
Change-Id: Ie3db8d29445f2cff06e2ee180f5dd454acedbae3
2025-07-17 23:07:54 +00:00
08b51dd130 Merge tag 'v1.6.0'
libwebp-1.6.0

- 6/30/2025 version 1.6.0
  This is a binary compatible release.
  API changes:
    - libwebp: WebPValidateDecoderConfig
  * additional x86 (AVX2, SSE2), general optimizations and compression
    improvements for lossless
  * `-mt` returns same results as single-threaded lossless (regressed in
    1.5.0, #426506716)
  * miscellaneous warning, bug & build fixes (#393104377, #397130631,
    #398288323, #398066379, #427503509)
  Tool updates:
    * cwebp can restrict the use of `-resize` with `-resize_mode` (#405437935)

Bug: webp:427525168

* tag 'v1.6.0':
  update ChangeLog
  webp_js/README.md: add some more code formatting (``)
  CMakeLists: add warning for incorrect emscripten config
  update ChangeLog
  api.md: add WebPValidateDecoderConfig to pseudocode
  update NEWS
  bump version to 1.6.0
  update AUTHORS

Change-Id: Ia4962eff9c197c42c77c9eadd35cdeee3586510e
2025-07-09 16:26:07 -07:00
4fa2191233 update ChangeLog
Bug: webp:427525168
Change-Id: Ic3542c736a4cea3ec3b6529fe546ce9267295169
v1.6.0
2025-07-07 17:20:00 -07:00
370aa5817e webp_js/README.md: add some more code formatting (``)
Bug: webp:427525168
Change-Id: I979d0e7406ecc482a5ebb7d94cc50117f8384acc
2025-07-07 15:34:31 -07:00
f83c6b328f CMakeLists: add warning for incorrect emscripten config
`-DWEBP_BUILD_WEBP_JS=1` requires `emcmake` and `emmake`. Attempt to
detect `emcmake` usage by checking for the `EMSCRIPTEN_VERSION`
variable and issue a warning if it is not set. This may help avoid a
surprising build error as `cmake` itself will succeed:

```
$ make
[...]
[100%] Building C object CMakeFiles/webp_wasm.dir/extras/webp_to_sdl.c.o
clang: error: no such file or directory: 'SDL2::SDL2'
```

Bug: webp:427525168
Change-Id: I4f5fa2ffbbc4123e28172f2b7ef952a1b1a687bf
2025-07-07 14:15:07 -07:00
6a3e656b6d update ChangeLog
Bug: webp:427525168
Change-Id: Ie3438cc33dc68170bb46cd4299a41230cff29e4d
v1.6.0-rc1
2025-07-01 15:18:52 -07:00
fa6f56496a BuildHuffmanTable: add an assert for offset[] bounds
And provide a clear comment explaining why the index of offset[] is
always checked within bounds.

Bug:webp:622
Change-Id: Id9b973a804b74c53dfb291f1a9dae649c0daed9d
2025-06-30 14:52:06 -07:00
bf0bf1e749 api.md: add WebPValidateDecoderConfig to pseudocode
This is similar to the `WebPValidateConfig()` call in the encode example.

Bug: webp:427525168
Change-Id: I475484cb1a5d581757f5a693da186138b3dfabb3
2025-06-30 12:26:15 -07:00
e8ae210d0b update NEWS
Bug: webp:427525168
Change-Id: I792a12dda98b1937da2bb92d4e1626caf7f44c28
2025-06-30 12:26:15 -07:00
ce53efd7ae bump version to 1.6.0
libwebp{,decoder} - 1.6.0
libwebp libtool - 9.0.2
libwebpdecoder libtool - 5.0.2

mux - 1.6.0
libtool - 4.2.1

demux - 1.6.0
libtool - 2.17.0

sharpyuv - 0.4.2
libtool - 1.2.1

Bug: webp:427525168
Change-Id: Icac046c653b8f0901867cb9680be0cad22314e45
2025-06-30 12:26:15 -07:00
1c3331702f update AUTHORS
Bug: webp:427525168
Change-Id: Ib7eef7f6b57e1f481be8f7200d4227dcbb53a0d9
2025-06-30 12:26:05 -07:00
85e098e58d webpmux: fix heap overflow w/-get/-set
If extra arguments after -get/-set matched one of the recognized
keywords ('icc', 'xmp', etc.), the parser would overwrite the
`config->args[]` allocation, as only one argument was expected.

The additional arguments are now treated as input files. This has the
side effect of allowing input files to be named the same as one of the
keywords.

Bug: webp:427503509
Change-Id: Ic48c94b75349109638e938781024be0a783ff267
2025-06-26 15:14:41 -07:00
418340d85b Merge "Make histogram allocation and access more readable and type-safe." into main 2025-06-24 13:02:34 -07:00
23ce76fa37 Merge "VP8BitReaderSetBuffer: move NULL check to call site" into main 2025-06-24 12:45:57 -07:00
bbf3cbb1be VP8BitReaderSetBuffer: move NULL check to call site
This is a refinement of
654bfb04 Avoid nullptr arithmetic in VP8BitReaderSetBuffer
and removes an unneeded/redundant check in 2 of the 3 calls to this
function:

* VP8InitBitReader: `start` is guaranteed to be non-NULL
* CopyParts0Data: `start` is allocated and checked

In `DoRemap()` `last_start` will be NULL before the partitions are
parsed. This is the only call that was missing a check. The offsetting
of a NULL pointer in `VP8BitReaderSetBuffer` was harmless in this case
as the bitreader will not be used meaningfully until there is enough
data to begin decoding partition 0. In that case the bitreader will be
initialized by `ParsePartitions()` and updated by `DoRemap()` when more
data is available.

Bug: 393104377
Change-Id: Ib44bc35e00e5129c592d742a2469420cd3d0e858
2025-06-24 12:02:27 -07:00
f6b87e03fc Fix const style guide
Change-Id: I771726110f8c62872da4bf7b6ac6c6511eba356c
2025-06-24 11:50:09 +02:00