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

Subscribers

People subscribed via source and target branches