Commit graph

31 commits

Author SHA1 Message Date
James Almer
75bd5056a4 avcodec/decode: use av_exif_get_tag_id() where useful
Removes dependency on exif_internal.h

Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 12:07:41 -03:00
James Almer
45dcfb2d60 avcodec/version_major: remove unnecessary define for an internal function
It being avpriv and not public, it can be removed in the next bump regardless of when it
happens.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-09-01 11:00:44 -03:00
Michael Niedermayer
76645e096f avcodec/exif: also copy zero termination for AV_TIFF_STRING
Fixes: out of array read
Fixes: 441131173/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_DEC_fuzzer-6700429212975104

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-08-27 15:46:35 +00:00
Leo Izen
ef9fe0fe0b avcodec/exif: avoid allocation failure on empty EXIF metadata
An EXIF IFD with 0 entries is legal, but does not contain metadata. We
should not attempt to allocate a struct with size zero in this case, as
this causes an allocation failure. Instead, we just leave the struct
empty.

Fixes: #20305.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-24 20:20:10 +00:00
Leo Izen
2398fddf6e avcodec/exif: avoid writing native-endian EXIF buffers
Currently there's platform-dependent behavior where if no endianness
is requested, it writes the buffers in native-endian. This breaks FATE
tests on big-endian architecture. This commit changes the default to
little-endian buffers upon writing.

Fixes: #20291.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-24 20:20:10 +00:00
James Almer
368b5e0ffc avcodec/exif: make the get and remove helpers take a flags argument as input
This makes the functions extensible, as future behavior change flags can be
introduced.

This is strictly speaking not an API break. Only if a user was setting
recursive to anything other than 1 it would now behave differently, but given
these functions have been in the tree for only a few days, the chances for that
are practically zero.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-24 12:34:15 +00:00
James Almer
5a9e5d8031 avcodec/exif: use ff_frame_new_side_data() to export display matrix
Otherwise, the user requested priority of packet side data will be ignored.
For this, move the relevant functions to decode.c, as they need access to an
AVCodecContext.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-08-21 22:48:16 +00:00
Leo Izen
7caa2a65d9
avcodec/exif: fix some coverity errors
This commit fixes some memory and security issues due to improper
sanitizing and checks.

Fixes:
 - CID 1665100..1665107

Signed-off-by: Leo Izen <leo.izen@gmail.com>
Reportedy-by: James Almer <jamrial@gmail.com>
2025-08-21 15:40:45 -04:00
Leo Izen
535a07d14e
avcodec/exif: add ff_exif_sanitize_ifd
This commit takes some of the sanitize code used by ff_exif_get_buffer
and exposes it as an ff_ API, so encoders who wish to modify the
sanitized IFD before calling av_exif_write can do so.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:48 -04:00
Leo Izen
93a8091015
avcodec/exif: add av_exif_get_entry
Add an API function to retrieve am AVExifEntry struct with a given TIFF
tag ID from the AVExifMetadata ifd struct.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:48 -04:00
Leo Izen
303f60684f
avcodec/exif: add av_exif_remove_entry
Add an API function that allows popping an exif entry out of the struct
entirely rather than requiring it be replaced with a default value.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:48 -04:00
Leo Izen
5caaadee79
avcodec/exif: add orientation ID and matrix conversion routines
Takes existing code that makes display matricies work with EXIF
orientation tags and expose the conversion as a public API.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:47 -04:00
Leo Izen
d3190a64c3
avcodec/pngenc: support writing EXIF profiles
Add support to write EXIF profiles using the new EXIF framework, namely
ff_exif_get_buffer, and writing them into eXIf chunks.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:47 -04:00
Leo Izen
f5ad1c910c
avcodec/exif: add ff_exif_get_buffer
Add a function to allow encoders to get a self-contained EXIF
buffer to write into an EXIF chunk.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:47 -04:00
Leo Izen
e3aa1154aa
avcodec/exif: remove ff_exif_decode_ifd
This function is no longer called and its functionality
can be accessed using the new API in exif.h as well as the
various internal attach functions in exif_internal.h.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:47 -04:00
Leo Izen
bfb17d2630
avcodec/exif: add deprecation guards for old avpriv_
Add FF_API_OLD_EXIF deprecation guard based on lavc version < 62 in
order to allow removing the avpriv_ next major version bump.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:47 -04:00
Leo Izen
ad77345a5d
avcodec/exif: add EXIF parser and struct API
This commit adds a structure to contain parsed EXIF metadata, as well
as code to read and write that struct from/to binary EXIF buffers. Some
internal functions have been moved to exif_internal.h. Code to read
from this new struct and write to an AVDictionary **dict has been added
as well in order to preserve interoperability with existing callers.
The only codec changes so far as of this commit are to call these
interop functions, but in future commits there will be codec changes to
use the new parsing routines instead.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:46 -04:00
Leo Izen
a99fff4e2d
avcodec/tiff_common: rename TIFF enum constants
This makes the enum TiffTypes public by moving it to the public header
exif.h and renaming it to AVTiffDataType, as well as adding an AV_
prefix in front of each of the entry names. This allows callers to use
enum AVTiffDataType without pulling in all of tiff_common.h, as that
header is not public.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2025-08-19 11:26:40 -04:00
Andreas Rheinhardt
2c882f4708 avcodec/exif: Move tag_list out of header
It is only used by exif.c (and e.g. EXIF_TAG_NAME_LENGTH
is an implementation detail anyway).
Also remove the sentinel, as it is used in conjunction
with FF_ARRAY_ELEMS.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-06-15 04:58:14 +02:00
Andreas Schneider
59c647bcf3 avcodec/exif: Don't include tiff.h in exif.h
The exif.h header doesn't use anything from tiff.h. We also just need
to include tiff_common.h in .c files where it actually used.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-14 11:33:53 +01:00
Andreas Rheinhardt
f15477169e avcodec/exif: Avoid allocation for small buffer
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-01-26 13:56:59 +01:00
James Almer
ae100046ca avcodec/exif: remove GetByteContext usage from avpriv_exif_decode_ifd()
This prevents potential ABI issues with GetByteContext.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-26 00:45:49 -03:00
Hendrik Leppkes
ce87711df5 exif: take a generic log context
The AVCodecContext is only used for logging, so instead take any valid log context.
This allows reusing the exif functions more easily in avformat.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-02 22:48:15 +01:00
Carl Eugen Hoyos
badcd3da81 Print a warning instead of requesting a sample for an invalid exif tag.
Fixes ticket #3792.
Reviewed-by: Thilo Borgmann
2014-07-24 11:58:11 +02:00
Michael Niedermayer
e70b9b32d5 avcodec/exif: do not follow 0 offsets
Fixes exif decoding failure of 1295328_300.jpg

Reviewed-by; Thilo Borgmann <thilo.borgmann@mail.de>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-04-20 17:02:16 +02:00
Michael Niedermayer
a94de50ba0 avcodec/exif/exif_add_metadata: add support for SSHORT & SBYTE
No working testcase, this omission was just spoted when the parser apparently went out of
sync.

Reviewed-by; Thilo Borgmann <thilo.borgmann@mail.de>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-04-20 17:01:46 +02:00
Thilo Borgmann
ec8789ac63 Reindent after last commit.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-04-05 03:32:11 +02:00
Thilo Borgmann
8c161d7884 lavc/exif: Make EXIF IFD decoding part of private API/ABI.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-04-05 03:31:56 +02:00
Michael Niedermayer
e40c96513e avcodec/exif: print bytes and undefined types as scalar lists
This prevents odd characters from ending in the fate test

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-09-29 12:19:47 +02:00
Thilo Borgmann
6a64b23d93 Update my email address. 2013-08-13 15:45:08 +02:00
Thilo Borgmann
ad0f7574ef avcodec: Add EXIF metadata parser to libavcodec.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-13 00:30:20 +02:00