From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Subject: [BlueZ, v3 6/9] sdp-xml: Optimise parsing large sequences
Date: Tue, 11 Aug 2026 16:54:09 +0200 [thread overview]
Message-ID: <20260811145704.1766949-7-hadess@hadess.net> (raw)
In-Reply-To: <20260811145704.1766949-1-hadess@hadess.net>
SDP sequences are stored as single-linked lists, so appending members
to a sequence requires finding the tail of the list before the
insertion.
Finding the tail of the list always starts at the beginning of the list,
so takes longer and longer as the list grows bigger.
Keep track of the tail to avoid that problem. This cuts down the
sequence_on_squared() test from around 3 to 4 seconds to less than
0.1 seconds.
---
src/sdp-xml.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index 816d19611f8b..97fb8b0c1af0 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -44,6 +44,7 @@ struct sdp_xml_data {
char type; /* 0 = Text or Hexadecimal */
char *name; /* Name, optional in the dtd */
/* TODO: What is it used for? */
+ sdp_data_t *tail; /* Tail for O(1) dataseq append */
};
struct context_data {
@@ -609,6 +610,7 @@ static void element_end(GMarkupParseContext *context,
if (ctx_data->stack_head->next && ctx_data->stack_head->data &&
ctx_data->stack_head->next->data) {
+ sdp_data_t *tail;
switch (ctx_data->stack_head->next->data->dtd) {
case SDP_SEQ8:
case SDP_SEQ16:
@@ -616,10 +618,17 @@ static void element_end(GMarkupParseContext *context,
case SDP_ALT8:
case SDP_ALT16:
case SDP_ALT32:
- ctx_data->stack_head->next->data->val.dataseq =
- sdp_seq_append(ctx_data->stack_head->next->data->val.dataseq,
- ctx_data->stack_head->data);
+ tail = ctx_data->stack_head->next->data->val.dataseq ?
+ ctx_data->stack_head->next->tail : NULL;
+ if (tail) {
+ sdp_seq_append(tail, ctx_data->stack_head->data);
+ } else {
+ ctx_data->stack_head->next->data->val.dataseq =
+ sdp_seq_append(NULL, ctx_data->stack_head->data);
+ }
+ ctx_data->stack_head->next->tail = ctx_data->stack_head->data;
ctx_data->stack_head->data = NULL;
+ ctx_data->stack_head->tail = NULL;
break;
}
--
2.55.0
next prev parent reply other threads:[~2026-08-11 15:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 14:54 [BlueZ, v3 0/9] 3 SDP XML security fixes Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 1/9] unit: Add test for sdp_xml_parse_record() Bastien Nocera
2026-08-11 16:33 ` 3 SDP XML security fixes bluez.test.bot
2026-08-11 14:54 ` [BlueZ, v3 2/9] sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 3/9] unit: Add test for sdp-xml type-confusion bug Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 4/9] sdp-xml: Fix memory leak when adding duplicate attributes Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 5/9] unit: Add test for sdp-xml duplicate attribute bug Bastien Nocera
2026-08-11 14:54 ` Bastien Nocera [this message]
2026-08-11 14:54 ` [BlueZ, v3 7/9] unit: Add test for slow element_end() append Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 8/9] sdp-xml: Fix stack overflow when converting large sequences to XML Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 9/9] unit: Add convert_sdp_record_to_xml() to SDP XML testing Bastien Nocera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260811145704.1766949-7-hadess@hadess.net \
--to=hadess@hadess.net \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox