openjp2/j2k: replace sprintf calls with snprintf 1450/head
authorMark Mentovai <mark@chromium.org>
Mon, 7 Nov 2022 14:32:02 +0000 (09:32 -0500)
committerEven Rouault <even.rouault@spatialys.com>
Tue, 7 Mar 2023 15:47:10 +0000 (16:47 +0100)
commit032b6e93cb38b42c365ebd5296ac08ccf5163feb
tree9aa86f3add69035ace5bd8e798f39287dd7782b7
parent480cc9d49775d018c19ce0e01f6be27858d63d39
openjp2/j2k: replace sprintf calls with snprintf

This makes it possible to build j2k.c without warnings using the macOS
13 SDK. Calls to sprintf are replaced with snprintf, passing appropriate
buffer sizes.

It doesn’t appear that any of the changed uses of sprintf were actually
unsafe, so no behavior change is expected aside from SDK compatibility.

The macOS 13 SDK deprecates sprintf as it’s difficult to use safely. The
deprecation warning message is visible when building C++, but it is not
normally visible when building plain C code due to a quirk in how
sprintf is declared in the SDK. However, the deprecation message is
visible when building plain C under Address Sanitizer
(-fsanitize=address). This discrepancy was discovered at
https://crbug.com/1381706 and reported to Apple with a copy at
https://openradar.appspot.com/FB11761475.

The macOS 13 SDK is packaged in Xcode 14.1, released on 2022-11-01. This
also affects the iOS 16 SDK and other 2022-era Apple OS SDKs packaged in
Xcode 14.0, released on 2022-09-12.

j2k.c is visible to the Chromium build via PDFium, and this change is
needed to allow Chromium to move forward to the macOS 13 SDK.

This change is limited to src/lib/openjp2. Other uses of sprintf were
found throughout openjpeg.
src/lib/openjp2/j2k.c