Skip to content

Commit 6196cf7

Browse files
lexbor: Merge upstream WHATWG URL and IDNA fixes
1 parent fa825cb commit 6196cf7

23 files changed

Lines changed: 324 additions & 32 deletions

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ PHP NEWS
2424
. Merge patches 8a14bc0 and f67ce4b, fixing a heap buffer overflow in
2525
:lexbor-contains() parsing and buffer overflows in malformed decode
2626
replay. (alexandre-daubois)
27+
. Merge patches lexbor/lexbor@859f100, lexbor/lexbor@a36e09a,
28+
lexbor/lexbor@b0f7412, lexbor/lexbor@1b215a8 and lexbor/lexbor@385afff,
29+
fixing dropped usernames containing an at sign, uninitialized memory in
30+
IDNA buffer growth, the encoding of a space before a query or fragment in
31+
an opaque path, the URLSearchParams tail pointer and fragment
32+
serialization without a query. (alexandre-daubois)
2733

2834
- MBString:
2935
. Fixed bug GH-23106 (mb_strpos() reads past the end of a haystack ending in

ext/lexbor/lexbor/unicode/idna.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ lxb_unicode_idna_realloc(lxb_codepoint_t *buf, const lxb_codepoint_t *buffer,
117117
lxb_codepoint_t *tmp;
118118

119119
nlen = ((*buf_end - buf) * 4) + len;
120-
120+
121121
if (buf == buffer) {
122122
tmp = lexbor_malloc(nlen * sizeof(lxb_codepoint_t));
123123
if (tmp == NULL) {
124124
return NULL;
125125
}
126+
127+
memcpy(tmp, buf, (*buf_p - buf) * sizeof(lxb_codepoint_t));
126128
}
127129
else {
128130
tmp = lexbor_realloc(buf, nlen * sizeof(lxb_codepoint_t));
@@ -458,13 +460,17 @@ lxb_unicode_idna_ascii_puny_cb(const lxb_char_t *data, size_t length, void *ctx,
458460

459461
if (asc->buf == asc->buffer) {
460462
tmp = lexbor_malloc(nlen);
463+
if (tmp == NULL) {
464+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
465+
}
466+
467+
memcpy(tmp, asc->buf, asc->p - asc->buf);
461468
}
462469
else {
463470
tmp = lexbor_realloc(asc->buf, nlen);
464-
}
465-
466-
if (tmp == NULL) {
467-
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
471+
if (tmp == NULL) {
472+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
473+
}
468474
}
469475

470476
asc->p = tmp + (asc->p - asc->buf);
@@ -711,13 +717,17 @@ lxb_unicode_idna_to_unicode_cb(const lxb_codepoint_t *part, size_t len,
711717

712718
if (asc->buf == asc->buffer) {
713719
tmp = lexbor_malloc(nlen);
720+
if (tmp == NULL) {
721+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
722+
}
723+
724+
memcpy(tmp, asc->buf, asc->p - asc->buf);
714725
}
715726
else {
716727
tmp = lexbor_realloc(asc->buf, nlen);
717-
}
718-
719-
if (tmp == NULL) {
720-
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
728+
if (tmp == NULL) {
729+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
730+
}
721731
}
722732

723733
asc->p = tmp + (asc->p - asc->buf);

ext/lexbor/lexbor/url/url.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,16 +1753,13 @@ lxb_url_parse_basic_h(lxb_url_parser_t *parser, lxb_url_t *url,
17531753
break;
17541754
}
17551755

1756-
if (pswd == NULL || !at_sign) {
1757-
tmp = (pswd != NULL) ? pswd - 1 : p;
1758-
1759-
if (tmp > begin) {
1760-
status = lxb_url_percent_encode_after_utf_8(begin, tmp,
1761-
&url->username, url->mraw,
1762-
LXB_URL_MAP_USERINFO, false);
1763-
if (status != LXB_STATUS_OK) {
1764-
lxb_url_parse_return(orig_data, buf, status);
1765-
}
1756+
tmp = (pswd != NULL) ? pswd - 1 : p;
1757+
if (tmp > begin) {
1758+
status = lxb_url_percent_encode_after_utf_8(begin, tmp,
1759+
&url->username, url->mraw,
1760+
LXB_URL_MAP_USERINFO, false);
1761+
if (status != LXB_STATUS_OK) {
1762+
lxb_url_parse_return(orig_data, buf, status);
17661763
}
17671764
}
17681765

@@ -2343,6 +2340,17 @@ lxb_url_parse_basic_h(lxb_url_parser_t *parser, lxb_url_t *url,
23432340
lxb_url_parse_return(orig_data, buf, status);
23442341
}
23452342

2343+
/* Encode only the space immediately before a query or fragment. */
2344+
if (p > begin && p[-1] == ' ') {
2345+
tmp_str.length--;
2346+
if (lexbor_str_append(&tmp_str, url->mraw,
2347+
(const lxb_char_t *) "%20", 3) == NULL)
2348+
{
2349+
lxb_url_parse_return(orig_data, buf,
2350+
LXB_STATUS_ERROR_MEMORY_ALLOCATION);
2351+
}
2352+
}
2353+
23462354
status = lxb_url_path_list_push(url, &tmp_str);
23472355
if (status != LXB_STATUS_OK) {
23482356
lxb_url_parse_return(orig_data, buf, status);
@@ -4907,7 +4915,7 @@ lxb_status_t
49074915
lxb_url_serialize_fragment(const lxb_url_t *url,
49084916
lexbor_serialize_cb_f cb, void *ctx)
49094917
{
4910-
if (url->query.data != NULL) {
4918+
if (url->fragment.data != NULL) {
49114919
return cb(url->fragment.data, url->fragment.length, ctx);
49124920
}
49134921

@@ -5106,6 +5114,8 @@ lxb_url_search_params_parse(lxb_url_search_params_t *search_params,
51065114
return status;
51075115
}
51085116

5117+
last = entry;
5118+
51095119
lexbor_str_init(&entry->value, mraw, 0);
51105120
if (entry->value.data == NULL) {
51115121
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;

ext/lexbor/patches/0001-Expose-line-and-column-information-for-use-in-PHP.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
33
Date: Sat, 26 Aug 2023 15:08:59 +0200
4-
Subject: [PATCH 01/12] Expose line and column information for use in PHP
4+
Subject: [PATCH 01/17] Expose line and column information for use in PHP
55

66
---
77
source/lexbor/dom/interfaces/node.h | 2 ++

ext/lexbor/patches/0002-Track-implied-added-nodes-for-options-use-in-PHP.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
33
Date: Mon, 14 Aug 2023 20:18:51 +0200
4-
Subject: [PATCH 02/12] Track implied added nodes for options use in PHP
4+
Subject: [PATCH 02/17] Track implied added nodes for options use in PHP
55

66
---
77
source/lexbor/html/tree.h | 3 +++

ext/lexbor/patches/0003-Patch-utilities-and-data-structure-to-be-able-to-gen.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
33
Date: Thu, 24 Aug 2023 22:57:48 +0200
4-
Subject: [PATCH 03/12] Patch utilities and data structure to be able to
4+
Subject: [PATCH 03/17] Patch utilities and data structure to be able to
55
generate smaller lookup tables
66

77
Changed the generation script to check if everything fits in 32-bits.

ext/lexbor/patches/0004-Remove-unused-upper-case-tag-static-data.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
33
Date: Wed, 29 Nov 2023 21:26:47 +0100
4-
Subject: [PATCH 04/12] Remove unused upper case tag static data
4+
Subject: [PATCH 04/17] Remove unused upper case tag static data
55

66
---
77
source/lexbor/tag/res.h | 2 ++

ext/lexbor/patches/0005-Shrink-size-of-static-binary-search-tree.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
33
Date: Wed, 29 Nov 2023 21:29:31 +0100
4-
Subject: [PATCH 05/12] Shrink size of static binary search tree
4+
Subject: [PATCH 05/17] Shrink size of static binary search tree
55

66
This also makes it more efficient on the data cache.
77
---

ext/lexbor/patches/0006-Patch-out-unused-CSS-style-code.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
33
Date: Sun, 7 Jan 2024 21:59:28 +0100
4-
Subject: [PATCH 06/12] Patch out unused CSS style code
4+
Subject: [PATCH 06/17] Patch out unused CSS style code
55

66
---
77
source/lexbor/css/rule.h | 2 ++

ext/lexbor/patches/0007-URL-fixed-setters-for-empty-hosts.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Alexander Borisov <lex.borisov@gmail.com>
33
Date: Fri, 26 Jun 2026 18:55:56 +0300
4-
Subject: [PATCH 07/12] URL: fixed setters for empty hosts.
4+
Subject: [PATCH 07/17] URL: fixed setters for empty hosts.
55
MIME-Version: 1.0
66
Content-Type: text/plain; charset=UTF-8
77
Content-Transfer-Encoding: 8bit

0 commit comments

Comments
 (0)