Merge ~sergiodj/ubuntu/+source/gstreamer1.0:use-g_memdup2-where-available into ubuntu/+source/gstreamer1.0:ubuntu/devel

Proposed by Sergio Durigan Junior
Status: Rejected
Rejected by: Sergio Durigan Junior
Proposed branch: ~sergiodj/ubuntu/+source/gstreamer1.0:use-g_memdup2-where-available
Merge into: ubuntu/+source/gstreamer1.0:ubuntu/devel
Diff against target: 287 lines (+255/-1)
4 files modified
debian/changelog (+8/-0)
debian/control (+2/-1)
debian/patches/0002-Use-g_memdup2-where-available-and-add-fallback-for-o.patch (+244/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
Utkarsh Gupta (community) Approve
Canonical Desktop Team Pending
Review via email: mp+405405@code.launchpad.net

Description of the change

Currently, libcamera FTBFS because gstreamer is using a deprecated g_memdup:

/usr/include/gstreamer-1.0/gst/base/gstbytereader.h: In function ‘guint8* gst_byte_reader_dup_data_unchecked(GstByteReader*, guint)’:
/usr/include/gstreamer-1.0/gst/base/gstbytereader.h:365:41: error: ‘void* g_memdup(gconstpointer, guint)’ is deprecated: Use 'g_memdup2' instead [-Werror=deprecated-declarations]
  365 | return (guint8 *) g_memdup (data, size);
      | ^
In file included from /usr/include/glib-2.0/glib.h:82,
                 from /usr/include/gstreamer-1.0/gst/gst.h:27,
                 from ../src/gstreamer/gstlibcamerasrc.h:12,
                 from ../src/gstreamer/gstlibcamerasrc.cpp:34:
/usr/include/glib-2.0/glib/gstrfuncs.h:257:23: note: declared here
  257 | gpointer g_memdup (gconstpointer mem,

This has been fixed by upstream gstreamer, and the patch is simple enough and I think we should adopt it as a delta while Debian doesn't pick it up:

https://gitlab.freedesktop.org/gstreamer/gstreamer/-/commit/b16e96dd878e0c5e7baeb8fad62ca43de1f66982

This is what this MP is about.

I tested rebuilding gstreamer with the upstream patch and then rebuilding libcamera with the new gstreamer package, and the build succeeded.

There's a PPA with the proposed gstreamer package and the libcamera rebuild here:

https://launchpad.net/~sergiodj/+archive/ubuntu/gstreamer-bug

To post a comment you must log in.
Revision history for this message
Utkarsh Gupta (utkarsh) wrote :

* Changelog:
  - [-] old content and logical tag match as expected
  - [✔] changelog entry correct version and targeted codename
  - [✔] changelog entries correct
  - [✔] update-maintainer has been run

* Actual changes:
  - [-] no upstream changes to consider
  - [✔] no further upstream version to consider
  - [-] debian changes look safe

* New Delta:
  - [✔] patches match what was proposed upstream
  - [✔] patches correctly included in debian/patches/series
  - [✔] patches have correct DEP3 metadata
  - [x] patches forwarded to Debian

I don't see the patches being forwarded however I believe that the new version that Debian will incorporate after the freeze should automatically pick this up. So not a problem, I believe. In case you've had different reasons for not forwarding, I'd be interested to hear them. Thanks!

* Build/Test:
  - [✔] build is ok
  - [✔] verified PPA package installs/uninstalls
  - [-] autopkgtest against the PPA package passes
  - [-] sanity checks test fine

I suppose you've done the above two things here, as mentioned in the comment, so I didn't re-do the whole thing.

+1. Thank you!

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks but the package is currently in sync with Debian and it would be nice to stay this way, could you try to propose the fix there?

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Thanks for the review, Utkarsh and Sebastien.

I agree it would be nice to keep the package as a sync. As I said, my rationale for proposing it as an MP is that (a) gstreamer has been blocking the migration of libcamera for a long time now, and (b) given that the fix comes from upstream, it should reach Ubuntu soon when Debian updates the package.

Either way, I will propose a Merge Request to the Debian package and see how it goes.

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :
Revision history for this message
Heather Ellsworth (hellsworth) wrote :

In an update impish vm, I installed the gstreamer and libcamera packages from the ppa. I installed libcamera-tools (built from the same source) and ran qcam (just from the cli) to test it and it segfaulted and this was logged in journalctl:

Jul 09 11:55:22 impish-fresh kernel: qcam[3176]: segfault at c ip 00007fa604e6c9e6 sp 00007ffee1c4f6b0 error 6 in libcamera.so.0.1.0[7fa604e27000+8d000]
Jul 09 11:55:22 impish-fresh kernel: Code: 00 00 4d 85 e4 74 0d 48 83 c4 08 4c 89 e0 5b 41 5c c3 66 90 4c 8b 25 31 88 07 00 48 89 c3 bf ba 00 00 00 31 c0 e8 da b3 fb ff <41> 89 44 24 0c 4c 89 e0 4c 89 a3 20 00 00 00 48 83 c4 08 5b 41 5c

I don't see any libcamera debugging symbols to dive down further.

Just to make sure qcam hasn't been broken, I went and made sure qcam worked worked in hirsute with the libcamera in the hirsute archive.

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks Heather for the testing, that's useful and sounds like something to investigate before uploading

Sergio, one other way to deal with the build failure which is due to '[-Werror=deprecated-declarations' would be to patch libcamera to not used that Werror...

still we should confirm that a rebuild is working and not leading also to a segfault

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

OK, thanks for the further comments guys, and thanks for testing, Heather.

To be totally honest with you guys, I wasn't expecting this MP to blow up like this. Of course, this is an apparent valid backport for gstreamer1.0, but if it affects libcamera and renders it unusable, then I totally agree that this needs more investigation.

This week was my +1 maintenance turn, and this MP was filed because of it. I have other higher priority tasks to complete in the upcoming weeks and I cannot promise that I will be able to continue investigating this issue.

I will put this MP in my TODO list, but it may be a while until I have the time to come back to it. So feel free to take it over from here, or to reject it and pursue another approach, of course. Bear in mind that it may be worth taking this discussion to the Merge Request I filed against Debian's gstreamer1.0, because if they accept and upload the change there it will quietly find its way to Ubuntu and then we will have a buildable-but-useless libcamera in the archive.

Lastly, I can happily enable the building of debuginfo in my PPA if Heather wants. Just let me know.

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

I won't have time to tackle this anytime soon, so I'm marking this MP as rejected. Hopefully it can be of use to someone who wants to continue the investigation.

Unmerged commits

bde453a... by Sergio Durigan Junior

changelog for 1.18.4-2ubuntu1

f61f468... by Sergio Durigan Junior

update-maintainer

6147cef... by Sergio Durigan Junior

  * d/p/0002-Use-g_memdup2-where-available-and-add-fallback-for-o.patch:
    Use g_memdup2 where available and add fallback to older GLib
    versions. (LP: #1931958)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/changelog b/debian/changelog
index 1c5d33b..8bd2ff6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
1gstreamer1.0 (1.18.4-2ubuntu1) impish; urgency=medium
2
3 * d/p/0002-Use-g_memdup2-where-available-and-add-fallback-for-o.patch:
4 Use g_memdup2 where available and add fallback to older GLib
5 versions. (LP: #1931958)
6
7 -- Sergio Durigan Junior <sergio.durigan@canonical.com> Thu, 08 Jul 2021 12:34:52 -0400
8
1gstreamer1.0 (1.18.4-2) unstable; urgency=medium9gstreamer1.0 (1.18.4-2) unstable; urgency=medium
210
3 * Upload to unstable.11 * Upload to unstable.
diff --git a/debian/control b/debian/control
index a5954eb..e70c1d4 100644
--- a/debian/control
+++ b/debian/control
@@ -1,7 +1,8 @@
1Source: gstreamer1.01Source: gstreamer1.0
2Section: libs2Section: libs
3Priority: optional3Priority: optional
4Maintainer: Maintainers of GStreamer packages <gstreamer1.0@packages.debian.org>4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5XSBC-Original-Maintainer: Maintainers of GStreamer packages <gstreamer1.0@packages.debian.org>
5Uploaders: Sebastian Dröge <slomo@debian.org>,6Uploaders: Sebastian Dröge <slomo@debian.org>,
6 Sjoerd Simons <sjoerd@debian.org>7 Sjoerd Simons <sjoerd@debian.org>
7Build-Depends: debhelper,8Build-Depends: debhelper,
diff --git a/debian/patches/0002-Use-g_memdup2-where-available-and-add-fallback-for-o.patch b/debian/patches/0002-Use-g_memdup2-where-available-and-add-fallback-for-o.patch
8new file mode 1006449new file mode 100644
index 0000000..6d35e3b
--- /dev/null
+++ b/debian/patches/0002-Use-g_memdup2-where-available-and-add-fallback-for-o.patch
@@ -0,0 +1,244 @@
1From: Doug Nazar <nazard@nazar.ca>
2Date: Fri, 23 Apr 2021 12:12:58 -0400
3Subject: Use g_memdup2() where available and add fallback for older GLib
4 versions
5
6glib 2.68 deprecates g_memdup(). Replace with g_memdup2() and
7add fallback if compiling against older versions, since we
8want to avoid deprecation warnings.
9
10Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/803>
11
12Origin: upstream, https://gitlab.freedesktop.org/gstreamer/gstreamer/-/commit/b16e96dd878e0c5e7baeb8fad62ca43de1f66982
13Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libcamera/+bug/1931958
14---
15 gst/glib-compat-private.h | 3 +++
16 gst/gstregistrychunks.c | 3 ++-
17 libs/gst/base/gstbitwriter.c | 6 ++++--
18 libs/gst/base/gstbytereader.c | 3 ++-
19 libs/gst/base/gstbytereader.h | 5 ++++-
20 libs/gst/base/gstbytewriter.c | 4 +++-
21 libs/gst/base/gstindex.c | 3 ++-
22 tests/check/libs/bitwriter.c | 3 ++-
23 tests/check/libs/bytereader.c | 3 ++-
24 tests/check/libs/bytewriter.c | 5 +++--
25 10 files changed, 27 insertions(+), 11 deletions(-)
26
27diff --git a/gst/glib-compat-private.h b/gst/glib-compat-private.h
28index 8f37de2..617a50e 100644
29--- a/gst/glib-compat-private.h
30+++ b/gst/glib-compat-private.h
31@@ -30,6 +30,9 @@ G_BEGIN_DECLS
32 /* copies */
33
34 /* adaptations */
35+#if !GLIB_CHECK_VERSION(2, 67, 4)
36+#define g_memdup2(ptr,sz) ((G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL))
37+#endif
38
39 G_END_DECLS
40
41diff --git a/gst/gstregistrychunks.c b/gst/gstregistrychunks.c
42index b352c45..80d0d4f 100644
43--- a/gst/gstregistrychunks.c
44+++ b/gst/gstregistrychunks.c
45@@ -40,6 +40,7 @@
46 #include <gst/gstinfo.h>
47 #include <gst/gstenumtypes.h>
48 #include <gst/gstpadtemplate.h>
49+#include "glib-compat-private.h"
50
51 #include <gst/gstregistrychunks.h>
52
53@@ -95,7 +96,7 @@ _strnlen (const gchar * str, gint maxlen)
54 gint _len = _strnlen (inptr, (endptr-inptr)); \
55 if (_len == -1) \
56 goto error_label; \
57- outptr = g_memdup ((gconstpointer)inptr, _len + 1); \
58+ outptr = g_memdup2 ((gconstpointer)inptr, _len + 1); \
59 inptr += _len + 1; \
60 }G_STMT_END
61
62diff --git a/libs/gst/base/gstbitwriter.c b/libs/gst/base/gstbitwriter.c
63index 2f7f56b..0947a68 100644
64--- a/libs/gst/base/gstbitwriter.c
65+++ b/libs/gst/base/gstbitwriter.c
66@@ -27,6 +27,8 @@
67 #define GST_BIT_WRITER_DISABLE_INLINES
68 #include "gstbitwriter.h"
69
70+#include "gst/glib-compat-private.h"
71+
72 /**
73 * SECTION:gstbitwriter
74 * @title: GstBitWriter
75@@ -200,7 +202,7 @@ gst_bit_writer_reset_and_get_data (GstBitWriter * bitwriter)
76
77 data = bitwriter->data;
78 if (bitwriter->owned)
79- data = g_memdup (data, bitwriter->bit_size >> 3);
80+ data = g_memdup2 (data, bitwriter->bit_size >> 3);
81 gst_bit_writer_reset (bitwriter);
82
83 return data;
84@@ -232,7 +234,7 @@ gst_bit_writer_reset_and_get_buffer (GstBitWriter * bitwriter)
85 /* we cannot rely on buffers allocated externally, thus let's dup
86 * the data */
87 if (data && !bitwriter->owned)
88- data = g_memdup (data, size);
89+ data = g_memdup2 (data, size);
90
91 buffer = gst_buffer_new ();
92 if (data != NULL) {
93diff --git a/libs/gst/base/gstbytereader.c b/libs/gst/base/gstbytereader.c
94index e9c2ec0..c0a16ef 100644
95--- a/libs/gst/base/gstbytereader.c
96+++ b/libs/gst/base/gstbytereader.c
97@@ -26,6 +26,7 @@
98 #define GST_BYTE_READER_DISABLE_INLINES
99 #include "gstbytereader.h"
100
101+#include "gst/glib-compat-private.h"
102 #include <string.h>
103
104 /**
105@@ -1222,7 +1223,7 @@ gst_byte_reader_dup_string_utf##bits (GstByteReader * reader, type ** str) \
106 *str = NULL; \
107 return FALSE; \
108 } \
109- *str = g_memdup (reader->data + reader->byte, size); \
110+ *str = g_memdup2 (reader->data + reader->byte, size); \
111 reader->byte += size; \
112 return TRUE; \
113 }
114diff --git a/libs/gst/base/gstbytereader.h b/libs/gst/base/gstbytereader.h
115index b988739..2130a8a 100644
116--- a/libs/gst/base/gstbytereader.h
117+++ b/libs/gst/base/gstbytereader.h
118@@ -362,7 +362,10 @@ static inline guint8 *
119 gst_byte_reader_dup_data_unchecked (GstByteReader * reader, guint size)
120 {
121 gconstpointer data = gst_byte_reader_get_data_unchecked (reader, size);
122- return (guint8 *) g_memdup (data, size);
123+ guint8 *dup_data = (guint8 *) g_malloc (size);
124+
125+ memcpy (dup_data, data, size);
126+ return dup_data;
127 }
128
129 /* Unchecked variants that should not be used */
130diff --git a/libs/gst/base/gstbytewriter.c b/libs/gst/base/gstbytewriter.c
131index 335f22f..aec1093 100644
132--- a/libs/gst/base/gstbytewriter.c
133+++ b/libs/gst/base/gstbytewriter.c
134@@ -25,6 +25,8 @@
135 #define GST_BYTE_WRITER_DISABLE_INLINES
136 #include "gstbytewriter.h"
137
138+#include "gst/glib-compat-private.h"
139+
140 /**
141 * SECTION:gstbytewriter
142 * @title: GstByteWriter
143@@ -236,7 +238,7 @@ gst_byte_writer_reset_and_get_data (GstByteWriter * writer)
144
145 data = (guint8 *) writer->parent.data;
146 if (!writer->owned)
147- data = g_memdup (data, writer->parent.size);
148+ data = g_memdup2 (data, writer->parent.size);
149 writer->parent.data = NULL;
150 gst_byte_writer_reset (writer);
151
152diff --git a/libs/gst/base/gstindex.c b/libs/gst/base/gstindex.c
153index d54e0fe..964508e 100644
154--- a/libs/gst/base/gstindex.c
155+++ b/libs/gst/base/gstindex.c
156@@ -61,6 +61,7 @@
157 #endif
158
159 #include <gst/gst.h>
160+#include "gst/glib-compat-private.h"
161
162 /* Index signals and args */
163 enum
164@@ -798,7 +799,7 @@ gst_index_add_associationv (GstIndex * index, gint id,
165 entry->type = GST_INDEX_ENTRY_ASSOCIATION;
166 entry->id = id;
167 entry->data.assoc.flags = flags;
168- entry->data.assoc.assocs = g_memdup (list, sizeof (GstIndexAssociation) * n);
169+ entry->data.assoc.assocs = g_memdup2 (list, sizeof (GstIndexAssociation) * n);
170 entry->data.assoc.nassocs = n;
171
172 gst_index_add_entry (index, entry);
173diff --git a/tests/check/libs/bitwriter.c b/tests/check/libs/bitwriter.c
174index d6f68d3..4628a5b 100644
175--- a/tests/check/libs/bitwriter.c
176+++ b/tests/check/libs/bitwriter.c
177@@ -29,6 +29,7 @@
178 #include <gst/check/gstcheck.h>
179 #include <gst/base/gstbitwriter.h>
180 #include <gst/base/gstbitreader.h>
181+#include "gst/glib-compat-private.h"
182
183 GST_START_TEST (test_initialization)
184 {
185@@ -76,7 +77,7 @@ GST_START_TEST (test_data)
186 fail_unless (gst_bit_writer_put_bits_uint64 (&writer, 0x45, 48));
187 fail_unless_equals_int (gst_bit_writer_get_remaining (&writer), 2048 - 71);
188 fail_unless (gst_bit_writer_align_bytes (&writer, 0));
189- data = g_memdup (sdata, sizeof (sdata));
190+ data = g_memdup2 (sdata, sizeof (sdata));
191 fail_unless (gst_bit_writer_put_bytes (&writer, data, sizeof (sdata)));
192
193 gst_bit_reader_init (&reader, gst_bit_writer_get_data (&writer), 256);
194diff --git a/tests/check/libs/bytereader.c b/tests/check/libs/bytereader.c
195index 24a2971..bc4c406 100644
196--- a/tests/check/libs/bytereader.c
197+++ b/tests/check/libs/bytereader.c
198@@ -27,6 +27,7 @@
199 #include <gst/gst.h>
200 #include <gst/check/gstcheck.h>
201 #include <gst/base/gstbytereader.h>
202+#include "gst/glib-compat-private.h"
203
204 #ifndef fail_unless_equals_int64
205 #define fail_unless_equals_int64(a, b) \
206@@ -574,7 +575,7 @@ GST_START_TEST (test_scan)
207 gint found;
208
209 /* dup so valgrind can detect out of bounds access more easily */
210- m = g_memdup (sync_data, sizeof (sync_data));
211+ m = g_memdup2 (sync_data, sizeof (sync_data));
212 gst_byte_reader_init (&reader, m, sizeof (sync_data));
213
214 found = gst_byte_reader_masked_scan_uint32_peek (&reader, 0xffffff00,
215diff --git a/tests/check/libs/bytewriter.c b/tests/check/libs/bytewriter.c
216index 89999af..c8017b8 100644
217--- a/tests/check/libs/bytewriter.c
218+++ b/tests/check/libs/bytewriter.c
219@@ -27,6 +27,7 @@
220 #include <gst/gst.h>
221 #include <gst/check/gstcheck.h>
222 #include <gst/base/gstbytewriter.h>
223+#include "gst/glib-compat-private.h"
224
225 GST_START_TEST (test_initialization)
226 {
227@@ -42,7 +43,7 @@ GST_START_TEST (test_initialization)
228 (&writer)), 0);
229 gst_byte_writer_reset (&writer);
230
231- data = g_memdup (sdata, sizeof (sdata));
232+ data = g_memdup2 (sdata, sizeof (sdata));
233 gst_byte_writer_init_with_data (&writer, data, sizeof (sdata), FALSE);
234 fail_unless_equals_int (gst_byte_writer_get_pos (&writer), 0);
235 fail_unless_equals_int (gst_byte_writer_get_size (&writer), 0);
236@@ -56,7 +57,7 @@ GST_START_TEST (test_initialization)
237 g_free (data);
238 data = tmp = NULL;
239
240- data = g_memdup (sdata, sizeof (sdata));
241+ data = g_memdup2 (sdata, sizeof (sdata));
242 gst_byte_writer_init_with_data (&writer, data, sizeof (sdata), TRUE);
243 fail_unless_equals_int (gst_byte_writer_get_pos (&writer), 0);
244 fail_unless_equals_int (gst_byte_writer_get_size (&writer), sizeof (sdata));
diff --git a/debian/patches/series b/debian/patches/series
index cbeba03..bc3b6bc 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
10001-registrybinary-Update-magic-version-string.patch10001-registrybinary-Update-magic-version-string.patch
20002-Use-g_memdup2-where-available-and-add-fallback-for-o.patch

Subscribers

People subscribed via source and target branches