Commit graph

1185 commits

Author SHA1 Message Date
Wim Taymans
e317edcfb9 pod: rework the parser
Make a new body.h file with some functions to deal with pod and their
body. Make the iter.h functions use mostly this.

Rework the parser so that it only uses body.h functions. With the separation
of pod+body, we can read and verify the pod once and then use the
verified copy to handle the rest of the body safely.

We do this because iter.h only works in pods in memory that doesn't change
because it is vulnerable to modifications of the data after verifying it.

The new parser is not vulnerable to this and will not cause invalid
memory access when used on shared memory. There is however no need for
atomic operations to read the headers, whever is read is either valid
and useable of invalid and rejected.

See #4822
2025-07-29 15:15:02 +02:00
Wim Taymans
87333537d2 pod: also check 0 terminted strings in copy_string
Use get_string() to get a pointer to the string in the pod so that we
also check if it has a 0 terminator.

Fix the test case now that is_string returns true even for non
zero-terminated strings.
2025-07-25 17:33:46 +02:00
Wim Taymans
b991e9acc9 pod: check string zero byte only when parsing
The _is_type() macros should simply check the type in the header and if
the size is large enough to look into the type specifics. Further
validation of the values should be done when the value is retrieved.

Following this logic, the String zero byte check should be done in the
get_string() function.
2025-07-25 17:33:46 +02:00
Wim Taymans
0f6b365138 pod: don't call deref in reserve bytes
We already know that we could succesfully allocate enough space for the
bytes because we checked that before so simply move to the body of the
new bytes pod. We don't need to do the extensive checks we do in deref.
2025-07-24 18:35:21 +02:00
Wim Taymans
0c33101a42 pod: remove unused function 2025-07-24 18:22:14 +02:00
Wim Taymans
a85c24e9ca builder: support building pod + data + suffix
Add a function that can build a pod from a pod definition, a body data
and a suffix.

We can use this to build strings and bytes and arrays like the other
primitives, which makes it possible to add them to choices or arrays.

Fixes #4588
2025-07-24 16:23:54 +02:00
Barnabás Pőcze
c7838cbbcb spa: node: io: fix typo in documentation
`SPA_IO_RATE_MATCH_ACTIVE` -> `SPA_IO_RATE_MATCH_FLAG_ACTIVE`
2025-07-23 21:26:29 +02:00
Wim Taymans
5b436abef7 pod: improve compare function
Use the area to compare two rectangles. Use the width to break a tie.

This way the sorting is at least a bit more predictable and independent
of the order of the arguments.
2025-07-22 14:19:08 +02:00
Wim Taymans
495d6ba796 pod: remove some size checks
These are already done by the caller.
2025-07-22 14:09:10 +02:00
Wim Taymans
e91c541446 pod: disable padding when in body
Disable the padding to pod alignment for everything when we are building
the body of an array or choice.

This makes it possible to use bytes or strings or any other pod of a
fixed size as entries in arrays or choice.
2025-07-22 13:58:11 +02:00
Wim Taymans
b904cb14a9 pod: do size check before calling type/size/data functions
Assume that all the functions that take a type/size/data from a pod have
at least the right number of bytes in the data for the given type.
Callers need to ensure this.

Fix the callers of such functions to always make sure they deref a pod
type/size/body into something of at least the min size of the type.
2025-07-22 13:14:17 +02:00
Wim Taymans
0a52f959ac pod: add a function to return the min size of a type 2025-07-22 13:13:05 +02:00
Wim Taymans
a03bbc79fe pod: fix compilation 2025-07-22 12:20:05 +02:00
Demi Marie Obenour
05bd4547d0 pod: parser: avoid unneeded integer division
SPA_POD_CHOICE_N_VALUES involves an integer division, which is slow.
Replace it with subtraction and comparison.

No functional change intended.
2025-07-22 10:19:33 +00:00
Wim Taymans
da1d4fb30c pod: also check choice size before cast
Do a more thorough test of the choice type by not only checking the type
but also if the size is at least large enough to be able to cast it to
the pod_choice type and look at the contents.
2025-07-22 12:14:06 +02:00
Wim Taymans
ed7398a64a pod: use _deref and _frame in safe place
In the filter, don't _deref or use _frame before we are going to add
more pods to the builder. If we are using a dynamic builder, the
dereffed pod might become invalid when the memory is reallocated.

Instead, take the offset of the frame and deref later when we are not
going to add more things.
2025-07-22 10:06:07 +02:00
Wim Taymans
ff7fb675f1 pod: avoid overflow in _frame() 2025-07-22 09:43:50 +02:00
Wim Taymans
36f288f884 pod: require at least 1 choice value in _can_collect()
We can't collect the choice value when there is none so check for the
number of choice values in _can_collect() as well.
2025-07-21 10:14:39 +02:00
Carlos Rafael Giani
eb3d14053d doc: spa: Add more docs about SPA_IO_Clock and driver operations 2025-07-16 10:58:48 +02:00
Wim Taymans
da9bd36cbb spa: return before entering the error branch
In the normal case we should not go into the error path.
2025-07-15 14:51:24 +02:00
Demi Marie Obenour
b04da87e38 pod: check that choices are not empty
Before using the contents of a choice, check that it is not empty to
avoid reading out of bounds.
2025-07-15 10:13:18 +02:00
Demi Marie Obenour
d37bdf5cbf pod: check for NULL strings in tag utils
SPA_POD_String allows SPA_TYPE_None PODs and turns them to NULL, so
check for them.
2025-07-15 10:13:18 +02:00
Demi Marie Obenour
edef57f6c3 pod: avoid modulo by 0
a % b is undefined behavior if b is 0.
2025-07-15 10:13:18 +02:00
Demi Marie Obenour
fb315b9050 *: Missing bounds checks in POD handling
There were missing bounds checks for ill-formed POD all over the place.
2025-07-15 10:13:17 +02:00
Demi Marie Obenour
7ac94f1a69 pod: ensure strings are NUL-terminated before calling strlen()
SPA_TYPE_String needs to be NUL-terminated, so check that in
spa_pod_compare_value().
2025-07-15 10:13:17 +02:00
Barnabás Pőcze
331bb2f1ed spa: debug: SPA_TYPE_Id is unsigned
The underlying type of `SPA_TYPE_Id` is `uint32_t`, so access
and print it as such.
2025-07-12 19:52:43 +00:00
Barnabás Pőcze
49d9d5e618 spa: param: video: add missing type info for color params
Add the missing type info for:

  * SPA_FORMAT_VIDEO_colorRange
  * SPA_FORMAT_VIDEO_colorMatrix
  * SPA_FORMAT_VIDEO_transferFunction
  * SPA_FORMAT_VIDEO_colorPrimaries
2025-07-12 21:18:23 +02:00
Wim Taymans
a188f1d29f pod: remove alignment checks
We currently often create pods in a uint8_t buffer, which is not aligned
to 8 and might cause deref and other problems.

We should either align the buffer we write into or maybe make the
builder add some padding before the buffer to align it. We have to be
careful with that when we assume the buffer start is the beginning of
the pod..

Fixes #4794
2025-07-10 16:56:26 +02:00
Demi Marie Obenour
b3bf5be1f6 *: Avoid macros that use casts where possible
Use direct field access when the type is known, instead of a macro that
includes a cast.

These were missed in e4fcbef89a.
2025-07-10 14:02:55 +00:00
Barnabás Pőcze
5cf84fa3fe spa: debug: pod: print custom properties with more detail
Previously, custom object properties were printed as "unknown",
and the offset (wrt. `SPA_PROP_START_CUSTOM`) was not displayed.
A custom property is distinct from an "unknown" one. Being able
to quickly differentiate the two is useful. Furthermore, knowing
the custom property id (i.e. the actual numeric id minus
`SPA_PROP_START_CUSTOM`) is also very helpful.

To address the above, print a custom property (i.e. anything with
an id at least `SPA_PROP_START_CUSTOM`) as follows:

  Spa:Pod:Object:Param:Props:Custom:123

where the last component is the custom property id.
2025-07-10 14:01:50 +00:00
Barnabás Pőcze
4a92ec35a6 spa: debug: pod: use the appropriate format specifiers
Use the appropriate format specifiers wrt. the signedness of the type,
as well as use the `PRI*N` macros for the `[u]intN_t` types.
2025-07-10 14:01:50 +00:00
Wim Taymans
d3eb06ab74 pod: improve array copy function
Make a new function to also returnt he child size and type.

Make a new function that accepts the array item size. Check that the
array item size and destination item size match before memcpy the array
contents. This avoids overflowing the target array with a malformed
array pod.
2025-07-08 10:11:11 +02:00
Wim Taymans
ce2f9eebb4 pod: avoid checking size or alignment
For the embedded children, they will always be aligned. We can also
avoid the max size checks for children because this is already checked
for the parent and with the remaining size check.

For arrays and choice we simply don't get any elements in the array when
the sizes are too large.
2025-07-08 10:06:51 +02:00
Wim Taymans
289b33281f pod: check size before getting pod contents
Before accessing the pod contents, check if the size is at least what we
expect it to be or else we might read out of bounds.
2025-07-07 19:40:24 +02:00
Wim Taymans
5f4b4b02f9 pod: remove the ALIGNED from the pod struct
We don't really want to do this here otherwise structs that include a
pod will be padded so that an array of those structs will be aligned.

This makes a test case fail where we have a struct with a choice_body
followed by 3 uint32_t enum values. The size with and without the
aligned attribute is different.
2025-07-07 12:07:05 +02:00
Wim Taymans
a0f5c4153f builder: avoid oveflow 2025-07-07 10:38:56 +02:00
Wim Taymans
8554c9d02a pod: enforce max pod size
Set a max pod size and add some more over and underflow checks
2025-07-07 10:38:56 +02:00
Wim Taymans
2011474936 pod: improve type checks some more 2025-07-07 10:38:56 +02:00
Demi Marie Obenour
e4fcbef89a pod: Improve type-safety in SPA POD code
Use direct field access when the type is known, instead of a macro that
includes a cast.
2025-07-07 10:38:56 +02:00
Wim Taymans
aa2289a25b pod: check pod alignment
Make a SPA_POD_ALIGN = 8 and make sure all pods are aligned to it. Use
the new constant to pad and check alignment. Make some new macros to
check for the pod type, alignment and minimal size.
2025-07-07 10:38:56 +02:00
Wim Taymans
b75ed93e51 pod: improve spa_pod_from_data()
spa_pod_from_data() is now safe against integer overflow.
2025-07-07 10:38:56 +02:00
Michael Olbrich
6294cbeb68 spa: add helper to determine if a video format is RGB 2025-06-27 12:57:01 +00:00
Michael Olbrich
20cdc9155f spa: video/color: add some more transfer functions and color primaries 2025-06-27 12:57:01 +00:00
Michael Olbrich
4c5e3f9015 spa: video/color: drop 'since' comments
These are GStreamer versions that make no sense here.
2025-06-27 12:57:01 +00:00
Pauli Virtanen
64f2f38ec4 bluez5: support LC3-24kHz HFP codec available on some Apple devices
Add support of HFP codec used on eg Apple AirPods 3+, transporting LC3
mono @ 24kHz
2025-06-13 22:15:29 +00:00
Wim Taymans
c1b5fb19ea spa: add volume_ramp_scale enum type info
And link it to the SPA_PROP_volumeRampScale property
2025-06-13 10:06:09 +02:00
Wim Taymans
c2eb173fdc spa: make the wave, pattern and ditherType Int
Properties of type Id should have a type of the enum with the possible
values associated with them.

The other types that don't have a fixed enumeration but are usually
mapped to some constant/description with PropInfo should be Int.

Fixes !2399
2025-06-13 10:06:09 +02:00
Wim Taymans
2393be4543 spa: add SPA_LATENCY_INFO_UNSET
Add a initializer for an unset latency info. Use this for combining
latency info.
2025-06-12 12:12:28 +02:00
Wim Taymans
190d49d874 loop: add docs about the locking 2025-06-10 18:00:01 +02:00
Wim Taymans
88963e9a9c Revert "loop: deprecate the hooks"
This reverts commit 550ec8c2a4.

Before hooks are still useful when integrating other fds in the pipewire
main loop.
2025-06-10 13:08:45 +02:00