iodine 0.8.4 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/iodine/fio-stl.h CHANGED
@@ -73,7 +73,7 @@ supports macros that will help detect and validate it's version.
73
73
  /** MINOR version: Deprecation, or significant features added. May break ABI. */
74
74
  #define FIO_VERSION_MINOR 8
75
75
  /** PATCH version: Bug fixes, minor features may be added. */
76
- #define FIO_VERSION_PATCH 4
76
+ #define FIO_VERSION_PATCH 5
77
77
  /** Build version: optional build info (string), i.e. "beta.02" */
78
78
  /* #define FIO_VERSION_BUILD */
79
79
 
@@ -1953,15 +1953,33 @@ Memory Leak Detection
1953
1953
  #define FIO_LEAK_COUNTER_SKIP_EXIT 0
1954
1954
  #endif
1955
1955
  #ifndef FIO___LEAK_COUNTER_DEF
1956
- /* Deceleration only, to be placed before the `extern` block if needed. */
1956
+ /**
1957
+ * Declares a named leak counter and its cleanup function, without defining
1958
+ * them.
1959
+ *
1960
+ * The counter itself is defined by `FIO_LEAK_COUNTER_DEF` in exactly one
1961
+ * translation unit (the `FIO_EXTERN_COMPLETE` one). Use this macro in
1962
+ * declarations-only `FIO_EXTERN` units that need to reference the counter.
1963
+ */
1957
1964
  #define FIO___LEAK_COUNTER_DEC(name) \
1958
- size_t FIO_NAME(fio___leak_counter, name)(size_t i);
1959
-
1960
- /* The shared counter + a (once per TU) `FIO_CALL_AFTER_EXIT` leak report. */
1965
+ size_t FIO_NAME(fio___leak_counter, name)(size_t i); \
1966
+ void FIO_NAME(fio___leak_counter_cleanup, name)(void *i);
1967
+ /**
1968
+ * Defines a named leak counter, its cleanup function and a constructor that
1969
+ * registers the cleanup with the `FIO_CALL_AFTER_EXIT` state event.
1970
+ *
1971
+ * Emits non-`static` symbols, so place it under the
1972
+ * `FIO_EXTERN_COMPLETE` / no-`FIO_EXTERN` gate. Declarations-only units use
1973
+ * `FIO_LEAK_COUNTER_DEC` instead.
1974
+ *
1975
+ * `FIO_LEAK_COUNTER_SKIP_EXIT` disables the exit registration.
1976
+ */
1961
1977
  #define FIO___LEAK_COUNTER_DEF(name) \
1962
1978
  size_t FIO_NAME(fio___leak_counter, name)(size_t i); \
1963
1979
  void FIO_NAME(fio___leak_counter_cleanup, name)(void *i); \
1964
- size_t FIO_WEAK FIO_NAME(fio___leak_counter, name)(size_t i) { \
1980
+ /* now do not need FIO_WEAK because all _DEF under completeTU gate,
1981
+ * deleted to see once-silent link issues explicitly not only on windows */ \
1982
+ size_t FIO_NAME(fio___leak_counter, name)(size_t i) { \
1965
1983
  static volatile size_t counter = 0; \
1966
1984
  size_t tmp = fio_atomic_add_fetch(&counter, i); \
1967
1985
  if (FIO_UNLIKELY(tmp == ((size_t)-1))) \
@@ -1972,7 +1990,7 @@ Memory Leak Detection
1972
1990
  "(%d) " FIO_MACRO2STR(name) " `free` after `free` detected!", \
1973
1991
  fio_getpid()); \
1974
1992
  } \
1975
- void FIO_WEAK FIO_NAME(fio___leak_counter_cleanup, name)(void *i) { \
1993
+ void FIO_NAME(fio___leak_counter_cleanup, name)(void *i) { \
1976
1994
  size_t counter = FIO_NAME(fio___leak_counter, name)((size_t)(uintptr_t)i); \
1977
1995
  FIO_LOG_DEBUG2("(%d) testing leaks for " FIO_MACRO2STR(name), \
1978
1996
  fio_getpid()); \
@@ -3711,6 +3729,12 @@ FIO_MIFN uint64_t fio_math_mul64_fold(uint64_t a, uint64_t b) {
3711
3729
  return r;
3712
3730
  }
3713
3731
 
3732
+ FIO_MIFN uint32_t fio_math_mul32_fold(uint32_t a, uint32_t b) {
3733
+ uint64_t r = (uint64_t)a * b;
3734
+ r ^= (r << 32);
3735
+ return (uint32_t)r;
3736
+ }
3737
+
3714
3738
  /**
3715
3739
  * Multi-precision long multiplication for `len` 64 bit words.
3716
3740
  *
@@ -9067,6 +9091,7 @@ Recursive inclusion management
9067
9091
  /* *****************************************************************************
9068
9092
  Leak Counter Helpers
9069
9093
  ***************************************************************************** */
9094
+ #undef FIO_LEAK_COUNTER_DEC
9070
9095
  #undef FIO_LEAK_COUNTER_DEF
9071
9096
  #undef FIO_LEAK_COUNTER_ON_ALLOC
9072
9097
  #undef FIO_LEAK_COUNTER_ON_FREE
@@ -9083,7 +9108,21 @@ Leak Counter Helpers
9083
9108
  #ifndef FIO_LEAK_COUNTER_SKIP_EXIT
9084
9109
  #define FIO_LEAK_COUNTER_SKIP_EXIT 0
9085
9110
  #endif
9111
+ /**
9112
+ * Declares a named leak counter and its cleanup function without defining
9113
+ * them. Use in declarations-only `FIO_EXTERN` translation units; the single
9114
+ * `FIO_EXTERN_COMPLETE` unit defines the counter with
9115
+ * `FIO_LEAK_COUNTER_DEF`.
9116
+ */
9086
9117
  #define FIO_LEAK_COUNTER_DEC FIO___LEAK_COUNTER_DEC
9118
+ /**
9119
+ * Defines a named leak counter, its cleanup function and a constructor that
9120
+ * registers the cleanup with the `FIO_CALL_AFTER_EXIT` state event.
9121
+ *
9122
+ * Emits non-`static` symbols, so it must appear in exactly one translation
9123
+ * unit (the `FIO_EXTERN_COMPLETE` one, or every unit in a header-only build).
9124
+ * `FIO_LEAK_COUNTER_SKIP_EXIT` disables the exit registration.
9125
+ */
9087
9126
  #define FIO_LEAK_COUNTER_DEF FIO___LEAK_COUNTER_DEF
9088
9127
  #define FIO_LEAK_COUNTER_ON_ALLOC FIO___LEAK_COUNTER_ON_ALLOC
9089
9128
  #define FIO_LEAK_COUNTER_ON_FREE FIO___LEAK_COUNTER_ON_FREE
@@ -10045,6 +10084,9 @@ Patches for Windows
10045
10084
  Windows initialization
10046
10085
  ***************************************************************************** */
10047
10086
 
10087
+ /* do startup once, in complete TU only */
10088
+ #if defined(FIO_EXTERN_COMPLETE) || !defined(FIO_EXTERN)
10089
+
10048
10090
  /* Enable console colors */
10049
10091
  FIO_CONSTRUCTOR(fio___windows_startup_housekeeping) {
10050
10092
  HANDLE c = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -10066,6 +10108,7 @@ FIO_CONSTRUCTOR(fio___windows_startup_housekeeping) {
10066
10108
  /* by default, windows read files using _O_TEXT, which affects behavior */
10067
10109
  _set_fmode(_O_BINARY);
10068
10110
  }
10111
+ #endif
10069
10112
 
10070
10113
  /* *****************************************************************************
10071
10114
  Inlined patched and MACRO statements
@@ -17079,6 +17122,8 @@ typedef struct {
17079
17122
  fio_buf_info_s cert;
17080
17123
  fio_buf_info_s trust;
17081
17124
  fio_buf_info_s pass;
17125
+ /** The URL query without the TLS hints at its head / tail (see below). */
17126
+ fio_buf_info_s query;
17082
17127
  bool tls;
17083
17128
  } fio_url_tls_info_s;
17084
17129
 
@@ -17127,6 +17172,19 @@ typedef struct {
17127
17172
  * https://example.com/?key=key_file_or_env_var&cert=cert_file_or_env_var&pass=key_password
17128
17173
  * wss://example.com/?key=key_file_or_env_var&cert=cert_file_or_env_var&pass=key_password
17129
17174
  * tcp://example.com/?key=key_file_or_env_var&cert=cert_file_or_env_var&pass=key_password
17175
+ *
17176
+ * The returned `query` omits the TLS hints at the head / tail of the URL query,
17177
+ * so it can be forwarded to a peer, i.e.: `u.query = fio_url_is_tls(u).query;`
17178
+ * Hints in the middle of the query are read and kept (pass-through for
17179
+ * application keys with colliding names).
17180
+ *
17181
+ * Only hints actually used are omitted: `tls` / `ssl` always; `trust` when it
17182
+ * has a value; `key` / `cert` only when both are set; `pass` / `password` only
17183
+ * alongside that pair. i.e.:
17184
+ *
17185
+ * ?tls&page=1&trust=sys => query: "page=1"
17186
+ * ?page=1&tls&sort=a => query: "page=1&tls&sort=a" (TLS: true)
17187
+ * ?key=API_KEY => query: "key=API_KEY" (no cert, not a hint)
17130
17188
  */
17131
17189
  SFUNC fio_url_tls_info_s fio_url_is_tls(fio_url_s u);
17132
17190
  /* *****************************************************************************
@@ -17457,9 +17515,35 @@ finish:
17457
17515
  return r;
17458
17516
  }
17459
17517
 
17518
+ /* Tests if a query element is a TLS hint used by `fio_url_is_tls`. */
17519
+ FIO_SFUNC bool fio___url_is_tls_hint(fio_url_query_each_s *i,
17520
+ fio_url_tls_info_s *r) {
17521
+ uint32_t name;
17522
+ switch (i->name.len) {
17523
+ case 3:
17524
+ name = fio_buf2u24_le(i->name.buf) | 0x202020U;
17525
+ return name == fio_buf2u24_le("tls") || name == fio_buf2u24_le("ssl") ||
17526
+ (r->key.len && name == fio_buf2u24_le("key"));
17527
+ case 4:
17528
+ name = fio_buf2u32u(i->name.buf) | 0x20202020UL;
17529
+ return (r->cert.len && name == fio_buf2u32u("cert")) ||
17530
+ (r->pass.len && name == fio_buf2u32u("pass"));
17531
+ case 5:
17532
+ return r->trust.len && i->value.len &&
17533
+ (fio_buf2u32u(i->name.buf) | 0x20202020UL) ==
17534
+ fio_buf2u32u("trus") &&
17535
+ (i->name.buf[4] | 0x20) == 't';
17536
+ case 8:
17537
+ return r->pass.len && (fio_buf2u64u(i->name.buf) |
17538
+ 0x2020202020202020ULL) == fio_buf2u64u("password");
17539
+ }
17540
+ return 0;
17541
+ }
17542
+
17460
17543
  /* Returns TLS data associated with the URL. */
17461
17544
  SFUNC fio_url_tls_info_s fio_url_is_tls(fio_url_s u) {
17462
- fio_url_tls_info_s r = {0};
17545
+ fio_url_tls_info_s r = {.query = u.query};
17546
+ bool hints = 0; /* `tls` / `ssl` keys don't leave other traces */
17463
17547
  switch (u.scheme.len) {
17464
17548
  case 3: /* wss || tls || ssl */
17465
17549
  r.tls =
@@ -17508,7 +17592,7 @@ SFUNC fio_url_tls_info_s fio_url_is_tls(fio_url_s u) {
17508
17592
  if (i.value.len)
17509
17593
  key = i.value;
17510
17594
  } else if (name == wrd_tls || name == wrd_ssl) {
17511
- r.tls = 1;
17595
+ r.tls = hints = 1;
17512
17596
  if (i.value.len && !(i.value.len == 1 && i.value.buf[0] == '1') &&
17513
17597
  !(i.value.len == 4 &&
17514
17598
  (fio_buf2u32u(i.value.buf) | 0x20202020UL) == wrd_true))
@@ -17539,6 +17623,33 @@ SFUNC fio_url_tls_info_s fio_url_is_tls(fio_url_s u) {
17539
17623
  r.trust = trust;
17540
17624
  r.tls = 1;
17541
17625
  }
17626
+ if (hints | (r.key.len != 0) | (r.trust.len != 0)) {
17627
+ /* omit the hints at the head / tail of the query */
17628
+ char *const end = u.query.buf + u.query.len;
17629
+ char *head = u.query.buf; /* first byte after the leading hints */
17630
+ char *tail = NULL; /* first byte of the trailing hints */
17631
+ bool leading = 1;
17632
+ FIO_URL_QUERY_EACH(u.query, i) {
17633
+ if (!fio___url_is_tls_hint(&i, &r)) {
17634
+ leading = 0;
17635
+ tail = NULL;
17636
+ continue;
17637
+ }
17638
+ if (leading)
17639
+ head = i.private___.buf ? i.private___.buf : end;
17640
+ else if (!tail)
17641
+ tail = i.name.buf;
17642
+ }
17643
+ if (leading) /* all hints */
17644
+ tail = head = end;
17645
+ else if (!tail)
17646
+ tail = end;
17647
+ else
17648
+ --tail; /* the '&' before the trailing hints */
17649
+ r.query = FIO_BUF_INFO2(head, (size_t)(tail - head));
17650
+ if (!r.query.len)
17651
+ r.query.buf = NULL;
17652
+ }
17542
17653
  }
17543
17654
  FIO_LOG_DDEBUG2(
17544
17655
  "URL TLS detection: %s (key: %u, cert: %u, trust: %u, pass: %u)",
@@ -17549,6 +17660,7 @@ SFUNC fio_url_tls_info_s fio_url_is_tls(fio_url_s u) {
17549
17660
  (unsigned)!!r.pass.len);
17550
17661
  return r;
17551
17662
  }
17663
+
17552
17664
  /* *****************************************************************************
17553
17665
  FIO_URL - Cleanup
17554
17666
  ***************************************************************************** */
@@ -31397,6 +31509,8 @@ SFUNC int fio_string_replace(fio_str_info_s *dest,
31397
31509
  if (start_pos < 0)
31398
31510
  start_pos = 0;
31399
31511
  }
31512
+ /* stage a self-source before truncation / movement can corrupt it */
31513
+ FIO___STRING_REPLACE_SELF(-1, dest, src, len);
31400
31514
  /* overflow-safe form of: (start_pos + overwrite_len >= dest->len) */
31401
31515
  if ((size_t)start_pos >= dest->len ||
31402
31516
  overwrite_len >= dest->len - (size_t)start_pos) {
@@ -31406,7 +31520,6 @@ SFUNC int fio_string_replace(fio_str_info_s *dest,
31406
31520
  }
31407
31521
  return fio_string_write(dest, reallocate, src, len);
31408
31522
  }
31409
- FIO___STRING_REPLACE_SELF(-1, dest, src, len);
31410
31523
  size_t move_start = start_pos + overwrite_len;
31411
31524
  size_t move_len = dest->len - (start_pos + overwrite_len);
31412
31525
  if (overwrite_len < len) {
@@ -32095,11 +32208,11 @@ SFUNC int fio_string_write_base32dec(fio_str_info_s *dest,
32095
32208
  255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
32096
32209
  255};
32097
32210
  int r = -1;
32098
- const uint8_t *e = (const uint8_t *)encoded;
32099
32211
  size_t symbols = 0, i = 0;
32100
- if (!dest || (!e && encoded_len))
32212
+ if (!dest || (!encoded && encoded_len))
32101
32213
  return r;
32102
32214
  FIO___STRING_REPLACE_SELF_SHRINK(-1, dest, encoded, encoded_len);
32215
+ const uint8_t *e = (const uint8_t *)encoded; /* after (possible) staging */
32103
32216
  /* validate and count data symbols (whitespace is free, `=` ends data) */
32104
32217
  for (; i < encoded_len; ++i) {
32105
32218
  const uint8_t d = base32decode[e[i]];
@@ -32739,6 +32852,7 @@ SFUNC int fio_string_write_html_unescape(fio_str_info_s *dest,
32739
32852
  int r = 0;
32740
32853
  if (!dest || !data || !data_len)
32741
32854
  return r;
32855
+ FIO___STRING_REPLACE_SELF_SHRINK(-1, dest, data, data_len);
32742
32856
  { /* decoded output is never longer than the input */
32743
32857
  size_t reserve = data_len;
32744
32858
  if (fio_string___write_validate_len(dest, reallocate, &reserve))
@@ -33718,8 +33832,9 @@ FIO_ASSERT_STATIC(FIO_GFM_REF_CACHE_SIZE > 0,
33718
33832
  #define FIO___GFM_MIN_FENCE_LEN 3
33719
33833
  #define FIO___GFM_MAX_ATX_HEADING 6
33720
33834
  #define FIO___GFM_MAX_ENTITY_LEN 32
33721
- /* Maximum bracket nesting for each link or image opener. Independent later
33722
- * openers remain eligible even when one opener exceeds the limit. */
33835
+ /* Maximum bracket nesting for each link or image opener, also used as the
33836
+ * destination parenthesis nesting limit (CommonMark permits such a limit).
33837
+ * Independent later openers remain eligible when one opener exceeds it. */
33723
33838
  #define FIO___GFM_MAX_INLINE_BRACKETS 64U
33724
33839
 
33725
33840
  /** Error codes — negative values are parser-generated. */
@@ -36377,13 +36492,14 @@ FIO_SFUNC char *fio___gfm_link_like_end(char *p, char *end) {
36377
36492
  char *after = s + 1;
36378
36493
  if (after < end && *after == '(') {
36379
36494
  char *q = after + 1;
36380
- int pd = 1;
36381
- while (q < end && pd) {
36495
+ unsigned pd = 1; /* same nesting cap as find_link: bounds inner checks */
36496
+ while (q < end && pd && pd <= FIO___GFM_MAX_INLINE_BRACKETS + 1) {
36382
36497
  if (*q == '\\' && q + 1 < end) {
36383
36498
  q += 2;
36384
36499
  continue;
36385
36500
  }
36386
- pd += (*q == '(') - (*q == ')');
36501
+ pd += (*q == '(');
36502
+ pd -= (*q == ')');
36387
36503
  ++q;
36388
36504
  }
36389
36505
  return pd ? NULL : q;
@@ -36654,7 +36770,11 @@ FIO_SFUNC char *fio___gfm_find_link(fio___gfm_parser_s *st,
36654
36770
  if (lp < end && *lp == '<') {
36655
36771
  ++lp;
36656
36772
  ds = lp;
36657
- while (lp < end && *lp != '>' && *lp != '\n' && *lp != '\r') {
36773
+ /* An unescaped '<' also ends (rejects) the destination, per spec. So a
36774
+ * failed scan stops at or before the next opener's '<' (never escaped,
36775
+ * it follows '(' or whitespace): failed scans are disjoint, O(n). */
36776
+ while (lp < end && *lp != '>' && *lp != '<' && *lp != '\n' &&
36777
+ *lp != '\r') {
36658
36778
  if (*lp == '\\' && lp + 1 < end) {
36659
36779
  lp += 2;
36660
36780
  continue;
@@ -36667,16 +36787,19 @@ FIO_SFUNC char *fio___gfm_find_link(fio___gfm_parser_s *st,
36667
36787
  ++lp;
36668
36788
  } else if (lp < end && *lp != ')') {
36669
36789
  ds = lp;
36670
- int pd = 0;
36790
+ /* Each failing opener leaves one unmatched '(' that later scans must
36791
+ * count, so the nesting cap bounds the work to O(n * cap). */
36792
+ unsigned pd = 0;
36671
36793
  while (lp < end && *lp != ' ' && *lp != '\t' && *lp != '\n' &&
36672
36794
  *lp != '\r') {
36673
36795
  if (*lp == '\\' && lp + 1 < end) {
36674
36796
  lp += 2;
36675
36797
  continue;
36676
36798
  }
36677
- if (*lp == '(')
36678
- ++pd;
36679
- else if (*lp == ')') {
36799
+ if (*lp == '(') {
36800
+ if (++pd > FIO___GFM_MAX_INLINE_BRACKETS)
36801
+ goto try_ref;
36802
+ } else if (*lp == ')') {
36680
36803
  if (pd == 0)
36681
36804
  break;
36682
36805
  --pd;
@@ -36701,14 +36824,16 @@ FIO_SFUNC char *fio___gfm_find_link(fio___gfm_parser_s *st,
36701
36824
  char close_ch = (open_ch == '(') ? ')' : open_ch;
36702
36825
  ++lp;
36703
36826
  ts = lp;
36704
- while (lp < end && *lp != close_ch) {
36827
+ /* A '('-title may not hold an unescaped '(' (spec). As with '<' above,
36828
+ * failed title scans then stop before the next same-kind opener. */
36829
+ while (lp < end && *lp != close_ch && !(open_ch == '(' && *lp == '(')) {
36705
36830
  if (*lp == '\\' && lp + 1 < end) {
36706
36831
  lp += 2;
36707
36832
  continue;
36708
36833
  }
36709
36834
  ++lp;
36710
36835
  }
36711
- if (lp >= end)
36836
+ if (lp >= end || *lp != close_ch)
36712
36837
  goto try_ref;
36713
36838
  te = lp;
36714
36839
  ++lp;
@@ -41176,8 +41301,10 @@ SFUNC int fio_queue_workers_add(fio_queue_s *q, size_t workers) {
41176
41301
  if (!q)
41177
41302
  return -1;
41178
41303
  while (workers > 255) {
41179
- fio_queue_workers_add(q, 128);
41180
- fio_queue_workers_add(q, 128);
41304
+ if (fio_queue_workers_add(q, 128))
41305
+ return -1;
41306
+ if (fio_queue_workers_add(q, 128))
41307
+ return -1;
41181
41308
  workers -= 256;
41182
41309
  }
41183
41310
  if (!workers)
@@ -82642,6 +82769,22 @@ FIO_IFUNC uint32_t fio___brotli_bits_get1(fio___brotli_bits_s *b) {
82642
82769
  return v;
82643
82770
  }
82644
82771
 
82772
+ /* Skip to the next byte boundary. RFC 7932 requires zero padding bits.
82773
+ * Returns -1 on non-zero padding, 0 otherwise. */
82774
+ FIO_IFUNC int fio___brotli_bits_align(fio___brotli_bits_s *b) {
82775
+ unsigned n = b->avail & 7; /* fills add whole bytes: rest of current byte */
82776
+ uint32_t pad = fio___brotli_bits_peek(b, n);
82777
+ fio___brotli_bits_drop(b, n);
82778
+ return 0 - (pad != 0);
82779
+ }
82780
+
82781
+ /* Return buffered whole bytes to the input (must be byte-aligned). */
82782
+ FIO_IFUNC void fio___brotli_bits_unread(fio___brotli_bits_s *b) {
82783
+ b->src -= b->avail >> 3;
82784
+ b->bits = 0;
82785
+ b->avail = 0;
82786
+ }
82787
+
82645
82788
  /* *****************************************************************************
82646
82789
  Huffman table builder - builds two-level lookup tables
82647
82790
  ***************************************************************************** */
@@ -82880,8 +83023,9 @@ FIO_IFUNC uint32_t fio___brotli_huff_decode(fio___brotli_bits_s *b,
82880
83023
  fio___brotli_bits_drop(b, root_bits);
82881
83024
  fio___brotli_bits_fill(b);
82882
83025
  unsigned sub_bits = FIO___BROTLI_ENTRY_SUB_BITS(entry);
82883
- if (b->avail < sub_bits)
82884
- return FIO___BROTLI_HUFF_ERR;
83026
+ /* Bits past `avail` are zero (or true future bits), so peeking the full
83027
+ * subtable width is safe; only the entry's actual codelen must be present
83028
+ * (checked below). Requiring `sub_bits` here rejected valid streams. */
82885
83029
  uint32_t sub_off = FIO___BROTLI_ENTRY_SUB_OFF(entry);
82886
83030
  uint32_t sub_idx = fio___brotli_bits_peek(b, sub_bits);
82887
83031
  entry = table[sub_off + sub_idx];
@@ -83026,6 +83170,9 @@ FIO_SFUNC uint32_t fio___brotli_read_prefix_code(fio___brotli_bits_s *b,
83026
83170
  cl_only = i;
83027
83171
  }
83028
83172
  }
83173
+ /* RFC 7932 Section 3.5: the code must be complete (or a single symbol) */
83174
+ if (cl_used != 1 && cl_space)
83175
+ return 0;
83029
83176
  if (cl_used == 1) {
83030
83177
  /* RFC 7932 section 3.5: a single used symbol has a zero-length code */
83031
83178
  for (unsigned i = 0; i < (1U << FIO___BROTLI_MAX_CL_LEN); i++)
@@ -83089,8 +83236,9 @@ FIO_SFUNC uint32_t fio___brotli_read_prefix_code(fio___brotli_bits_s *b,
83089
83236
  if (b->error)
83090
83237
  return 0;
83091
83238
  uint32_t repeat_delta = repeat - old_repeat;
83092
- /* Apply repeat_delta symbols */
83093
- for (uint32_t r = 0; r < repeat_delta && sym_count < alphabet_size; r++) {
83239
+ if (repeat_delta > alphabet_size - sym_count)
83240
+ return 0; /* repeat overflows the alphabet */
83241
+ for (uint32_t r = 0; r < repeat_delta; r++) {
83094
83242
  lengths[sym_count++] = (uint8_t)new_len;
83095
83243
  if (new_len)
83096
83244
  space -= (32768U >> new_len);
@@ -83098,6 +83246,9 @@ FIO_SFUNC uint32_t fio___brotli_read_prefix_code(fio___brotli_bits_s *b,
83098
83246
  }
83099
83247
  }
83100
83248
 
83249
+ /* RFC 7932 Section 3.5: the code must be complete (Kraft sum == 1) */
83250
+ if (space)
83251
+ return 0;
83101
83252
  /* Fill remaining with zeros */
83102
83253
  while (sym_count < alphabet_size)
83103
83254
  lengths[sym_count++] = 0;
@@ -83245,7 +83396,9 @@ FIO_SFUNC int fio___brotli_read_context_map(fio___brotli_bits_s *b,
83245
83396
  } else if (sym <= rlemax) {
83246
83397
  /* RLE zero: repeat 0 for (1 << sym) + read_bits(sym) times */
83247
83398
  uint32_t rep = (1U << sym) + fio___brotli_bits_get(b, sym);
83248
- for (uint32_t r = 0; r < rep && i < map_size; r++)
83399
+ if (rep > map_size - i)
83400
+ return -1; /* run overflows the context map */
83401
+ for (uint32_t r = 0; r < rep; r++)
83249
83402
  map[i++] = 0;
83250
83403
  } else {
83251
83404
  uint32_t val = sym - rlemax;
@@ -83434,6 +83587,61 @@ FIO_SFUNC void fio___brotli_decode_iac(uint32_t cmd,
83434
83587
  *dist_code_zero = dz[block];
83435
83588
  }
83436
83589
 
83590
+ /* Meta-block header kinds (fio___brotli_read_mb_header results). */
83591
+ #define FIO___BROTLI_MB_ERR 0 /* invalid or truncated header */
83592
+ #define FIO___BROTLI_MB_SKIP 1 /* ISLASTEMPTY or metadata (already skipped) */
83593
+ #define FIO___BROTLI_MB_RAW 2 /* uncompressed: input unread, src at data */
83594
+ #define FIO___BROTLI_MB_CMP 3 /* compressed: bit reader at the body */
83595
+
83596
+ /**
83597
+ * Read one meta-block header (RFC 7932 Section 9.2), rejecting non-zero
83598
+ * reserved / padding bits and exuberant (zero high) length nibbles / bytes.
83599
+ * Metadata blocks are skipped. Sets `*is_last` and `*mlen`.
83600
+ */
83601
+ FIO_SFUNC unsigned fio___brotli_read_mb_header(fio___brotli_bits_s *b,
83602
+ int *is_last,
83603
+ uint32_t *mlen) {
83604
+ fio___brotli_bits_fill(b);
83605
+ *is_last = (int)fio___brotli_bits_get1(b);
83606
+ *mlen = 0;
83607
+ if (*is_last && fio___brotli_bits_get1(b)) /* ISLASTEMPTY */
83608
+ return b->error ? FIO___BROTLI_MB_ERR : FIO___BROTLI_MB_SKIP;
83609
+ uint32_t mnibbles = fio___brotli_bits_get(b, 2);
83610
+ if (mnibbles == 3) { /* metadata (allowed with ISLAST as well) */
83611
+ if (fio___brotli_bits_get1(b))
83612
+ return FIO___BROTLI_MB_ERR; /* reserved bit */
83613
+ uint32_t nbytes = fio___brotli_bits_get(b, 2);
83614
+ size_t skip = 0;
83615
+ if (nbytes) {
83616
+ uint32_t v = fio___brotli_bits_get(b, nbytes * 8);
83617
+ if (nbytes > 1 && !(v >> ((nbytes - 1) * 8)))
83618
+ return FIO___BROTLI_MB_ERR; /* exuberant MSKIPLEN byte */
83619
+ skip = (size_t)v + 1;
83620
+ }
83621
+ if (fio___brotli_bits_align(b) || b->error)
83622
+ return FIO___BROTLI_MB_ERR;
83623
+ fio___brotli_bits_unread(b);
83624
+ if (skip > (size_t)(b->end - b->src))
83625
+ return FIO___BROTLI_MB_ERR;
83626
+ b->src += skip;
83627
+ return FIO___BROTLI_MB_SKIP;
83628
+ }
83629
+ uint32_t nibbles = mnibbles + 4;
83630
+ uint32_t v = fio___brotli_bits_get(b, nibbles * 4);
83631
+ if (nibbles > 4 && !(v >> ((nibbles - 1) * 4)))
83632
+ return FIO___BROTLI_MB_ERR; /* exuberant MLEN nibble */
83633
+ *mlen = v + 1;
83634
+ if (!*is_last && fio___brotli_bits_get1(b)) { /* ISUNCOMPRESSED */
83635
+ if (fio___brotli_bits_align(b) || b->error)
83636
+ return FIO___BROTLI_MB_ERR;
83637
+ fio___brotli_bits_unread(b);
83638
+ if (*mlen > (size_t)(b->end - b->src))
83639
+ return FIO___BROTLI_MB_ERR;
83640
+ return FIO___BROTLI_MB_RAW;
83641
+ }
83642
+ return b->error ? FIO___BROTLI_MB_ERR : FIO___BROTLI_MB_CMP;
83643
+ }
83644
+
83437
83645
  /**
83438
83646
  * Scan remaining meta-block headers in a Brotli stream, summing MLEN values.
83439
83647
  * Used after buffer overflow to determine total required output size.
@@ -83444,59 +83652,14 @@ FIO_SFUNC size_t fio___brotli_scan_remaining_mlen(fio___brotli_bits_s *bits) {
83444
83652
  size_t total = 0;
83445
83653
  int is_last = 0;
83446
83654
  while (!is_last) {
83447
- fio___brotli_bits_fill(bits);
83448
- is_last = (int)fio___brotli_bits_get1(bits);
83449
-
83450
- /* ISLASTEMPTY */
83451
- if (is_last && fio___brotli_bits_get1(bits))
83452
- break;
83453
- if (bits->error)
83454
- return 0;
83455
-
83456
- /* Meta-block length (MLEN) */
83457
- uint32_t mnibbles = fio___brotli_bits_get(bits, 2);
83458
- if (bits->error)
83459
- return 0;
83460
- if (mnibbles == 3) {
83461
- /* Metadata or empty meta-block */
83462
- if (!is_last) {
83463
- if (fio___brotli_bits_get1(bits))
83464
- return 0; /* reserved bit */
83465
- uint32_t mskipbytes = fio___brotli_bits_get(bits, 2);
83466
- if (mskipbytes > 0) {
83467
- uint32_t mskiplen = fio___brotli_bits_get(bits, mskipbytes * 8) + 1;
83468
- if (bits->avail & 7)
83469
- fio___brotli_bits_drop(bits, bits->avail & 7);
83470
- bits->src -= bits->avail / 8;
83471
- if (bits->error || mskiplen > (size_t)(bits->end - bits->src))
83472
- return 0;
83473
- bits->src += mskiplen;
83474
- bits->bits = 0;
83475
- bits->avail = 0;
83476
- } else {
83477
- if (bits->avail & 7)
83478
- fio___brotli_bits_drop(bits, bits->avail & 7);
83479
- }
83480
- }
83481
- continue;
83482
- }
83483
-
83484
- uint32_t mlen_nibbles = mnibbles + 4;
83485
- uint32_t mlen = fio___brotli_bits_get(bits, mlen_nibbles * 4) + 1;
83486
- if (bits->error || mlen > SIZE_MAX - total)
83655
+ uint32_t mlen;
83656
+ unsigned kind = fio___brotli_read_mb_header(bits, &is_last, &mlen);
83657
+ if (kind == FIO___BROTLI_MB_ERR || mlen > SIZE_MAX - total)
83487
83658
  return 0;
83488
83659
  total += mlen;
83489
-
83490
- /* Check for uncompressed meta-block */
83491
- if (!is_last && fio___brotli_bits_get1(bits)) {
83492
- /* Uncompressed: skip MLEN raw bytes */
83493
- if (bits->avail & 7)
83494
- fio___brotli_bits_drop(bits, bits->avail & 7);
83495
- bits->src -= (bits->avail / 8);
83496
- bits->bits = 0;
83497
- bits->avail = 0;
83498
- if (bits->error || mlen > (size_t)(bits->end - bits->src))
83499
- return 0;
83660
+ if (kind == FIO___BROTLI_MB_SKIP)
83661
+ continue;
83662
+ if (kind == FIO___BROTLI_MB_RAW) {
83500
83663
  bits->src += mlen;
83501
83664
  continue;
83502
83665
  }
@@ -83604,57 +83767,13 @@ SFUNC size_t fio_brotli_decompress(void *out,
83604
83767
  /* Process meta-blocks */
83605
83768
  int is_last = 0;
83606
83769
  while (!is_last) {
83607
- fio___brotli_bits_fill(&bits);
83608
-
83609
- is_last = (int)fio___brotli_bits_get1(&bits);
83610
-
83611
- /* ISLASTEMPTY */
83612
- if (is_last && fio___brotli_bits_get1(&bits))
83613
- break;
83614
-
83615
- /* Meta-block length (MLEN) */
83616
- uint32_t mnibbles = fio___brotli_bits_get(&bits, 2);
83617
- if (bits.error)
83770
+ uint32_t mlen;
83771
+ unsigned kind = fio___brotli_read_mb_header(&bits, &is_last, &mlen);
83772
+ if (kind == FIO___BROTLI_MB_ERR)
83618
83773
  return 0;
83619
- if (mnibbles == 3) {
83620
- /* Metadata or empty meta-block */
83621
- if (!is_last) {
83622
- if (fio___brotli_bits_get1(&bits))
83623
- return 0; /* reserved bit */
83624
- uint32_t mskipbytes = fio___brotli_bits_get(&bits, 2);
83625
- if (mskipbytes > 0) {
83626
- uint32_t mskiplen = fio___brotli_bits_get(&bits, mskipbytes * 8) + 1;
83627
- if (bits.avail & 7)
83628
- fio___brotli_bits_drop(&bits, bits.avail & 7);
83629
- bits.src -= bits.avail / 8;
83630
- if (bits.error || mskiplen > (size_t)(bits.end - bits.src))
83631
- return 0;
83632
- bits.src += mskiplen;
83633
- bits.bits = 0;
83634
- bits.avail = 0;
83635
- } else {
83636
- if (bits.avail & 7)
83637
- fio___brotli_bits_drop(&bits, bits.avail & 7);
83638
- }
83639
- }
83774
+ if (kind == FIO___BROTLI_MB_SKIP)
83640
83775
  continue;
83641
- }
83642
-
83643
- uint32_t mlen_nibbles = mnibbles + 4;
83644
- uint32_t mlen = fio___brotli_bits_get(&bits, mlen_nibbles * 4) + 1;
83645
- if (bits.error)
83646
- return 0;
83647
-
83648
- /* Check for uncompressed meta-block */
83649
- if (!is_last && fio___brotli_bits_get1(&bits)) {
83650
- /* Align to byte boundary and push back unused bits */
83651
- if (bits.avail & 7)
83652
- fio___brotli_bits_drop(&bits, bits.avail & 7);
83653
- bits.src -= (bits.avail / 8);
83654
- bits.bits = 0;
83655
- bits.avail = 0;
83656
- if (bits.error || mlen > (size_t)(bits.end - bits.src))
83657
- return 0;
83776
+ if (kind == FIO___BROTLI_MB_RAW) {
83658
83777
  if (mlen > out_len - pos) {
83659
83778
  /* Buffer overflow on uncompressed meta-block.
83660
83779
  * Add remaining bytes and scan subsequent headers. */
@@ -84051,7 +84170,10 @@ SFUNC size_t fio_brotli_decompress(void *out,
84051
84170
  return 0;
84052
84171
  }
84053
84172
 
84054
- return bits.error ? 0 : pos;
84173
+ /* Bits after the last meta-block, up to the byte boundary, must be zero. */
84174
+ if (fio___brotli_bits_align(&bits) || bits.error)
84175
+ return 0;
84176
+ return pos;
84055
84177
  }
84056
84178
 
84057
84179
  /* *****************************************************************************
@@ -85261,13 +85383,17 @@ FIO_SFUNC void fio___brotli_dict_ht_build(void) {
85261
85383
  FIO_SFUNC uint32_t fio___brotli_dict_find(const uint8_t *src,
85262
85384
  uint32_t src_len,
85263
85385
  uint32_t pos,
85386
+ size_t stream_pos,
85264
85387
  uint32_t window_size,
85265
85388
  uint32_t *out_copy_len,
85266
85389
  uint32_t *out_distance,
85267
85390
  int32_t *out_score) {
85268
85391
  if (pos + 4 > src_len)
85269
85392
  return 0;
85270
- uint32_t max_backward = (pos < window_size) ? pos : window_size;
85393
+ /* RFC 7932 Section 8: max_backward depends on the absolute stream position
85394
+ * (not the chunk-local `pos`), since decoders track total output. */
85395
+ uint32_t max_backward =
85396
+ (stream_pos < (size_t)window_size) ? (uint32_t)stream_pos : window_size;
85271
85397
  uint32_t h = fio___brotli_dict_hash4(src + pos);
85272
85398
  uint32_t base = h * 2;
85273
85399
  uint32_t best_len = 0;
@@ -85911,6 +86037,7 @@ SFUNC size_t fio_brotli_compress FIO_NOOP(void *out,
85911
86037
  uint32_t dict_len = fio___brotli_dict_find(src,
85912
86038
  src_len,
85913
86039
  pos,
86040
+ chunk_off + pos,
85914
86041
  window_size,
85915
86042
  &dict_copy_len,
85916
86043
  &dict_dist,
@@ -86454,8 +86581,10 @@ SFUNC size_t fio_brotli_compress FIO_NOOP(void *out,
86454
86581
  if (bs_remaining > 0)
86455
86582
  bs_remaining--;
86456
86583
  } else if (use_context_modeling) {
86457
- uint8_t p1 = p > 0 ? src[p - 1] : 0;
86458
- uint8_t p2 = p > 1 ? src[p - 2] : 0;
86584
+ /* p1/p2 span meta-blocks: use the absolute stream position */
86585
+ size_t ap = chunk_off + p;
86586
+ uint8_t p1 = ap > 0 ? in_bytes[ap - 1] : 0;
86587
+ uint8_t p2 = ap > 1 ? in_bytes[ap - 2] : 0;
86459
86588
  uint32_t ctx =
86460
86589
  (uint32_t)fio___brotli_context_lut[cmode * 512 + p1] |
86461
86590
  (uint32_t)fio___brotli_context_lut[cmode * 512 + 256 + p2];
@@ -86831,8 +86960,10 @@ SFUNC size_t fio_brotli_compress FIO_NOOP(void *out,
86831
86960
  if (bs_remaining > 0)
86832
86961
  bs_remaining--;
86833
86962
  } else if (use_context_modeling) {
86834
- uint8_t p1 = p > 0 ? src[p - 1] : 0;
86835
- uint8_t p2 = p > 1 ? src[p - 2] : 0;
86963
+ /* p1/p2 span meta-blocks: use the absolute stream position */
86964
+ size_t ap = chunk_off + p;
86965
+ uint8_t p1 = ap > 0 ? in_bytes[ap - 1] : 0;
86966
+ uint8_t p2 = ap > 1 ? in_bytes[ap - 2] : 0;
86836
86967
  uint32_t ctx =
86837
86968
  (uint32_t)fio___brotli_context_lut[cmode * 512 + p1] |
86838
86969
  (uint32_t)fio___brotli_context_lut[cmode * 512 + 256 + p2];
@@ -86902,6 +87033,10 @@ Cleanup
86902
87033
 
86903
87034
  #undef FIO___BROTLI_HUFF_BITS
86904
87035
  #undef FIO___BROTLI_HUFF_SIZE
87036
+ #undef FIO___BROTLI_MB_ERR
87037
+ #undef FIO___BROTLI_MB_SKIP
87038
+ #undef FIO___BROTLI_MB_RAW
87039
+ #undef FIO___BROTLI_MB_CMP
86905
87040
  #undef FIO___BROTLI_HUFF_MASK
86906
87041
  #undef FIO___BROTLI_MAX_CODE_LEN
86907
87042
  #undef FIO___BROTLI_MAX_CL_LEN
@@ -105941,11 +106076,18 @@ Internal helper types (`FIO___RECURSIVE_INCLUDE` other than 99) are `static`
105941
106076
  (see `001 header.h`), so every translation unit needs their implementation,
105942
106077
  even a declarations-only `FIO_EXTERN` one (e.g., FIOBJ inline constructors).
105943
106078
  ***************************************************************************** */
106079
+
106080
+ /* definition in complete TU only */
106081
+ #if defined(FIO_EXTERN_COMPLETE) || !defined(FIO_EXTERN)
106082
+ FIO_LEAK_COUNTER_DEF(FIO_REF_NAME)
106083
+ #endif
106084
+
105944
106085
  #if defined(FIO_EXTERN_COMPLETE) || !defined(FIO_EXTERN) || \
105945
106086
  (defined(FIO___RECURSIVE_INCLUDE) && (FIO___RECURSIVE_INCLUDE + 1) != 100)
105946
106087
 
105947
- /* static helpers exist in declarations-only TUs too: report leaks once */
105948
- FIO_LEAK_COUNTER_DEF(FIO_REF_NAME)
106088
+ /* static helpers exist in declarations-only TUs too: report leaks once,
106089
+ * use _DEC (enough to be seen in fiobj_), not _DEF that is in only one TU */
106090
+ FIO_LEAK_COUNTER_DEC(FIO_REF_NAME)
105949
106091
 
105950
106092
  /** Allocates a reference counted object. */
105951
106093
  #ifdef FIO_REF_FLEX_TYPE
@@ -109315,7 +109457,9 @@ struct fio_io_functions_s {
109315
109457
  *
109316
109458
  * Listeners pass the result to every accepted connection as is
109317
109459
  * (`fio_io_attach_fd` takes ownership); `start` handles a NULL context (the
109318
- * bundled TLS backends close such connections). Defaults to returning NULL.
109460
+ * bundled TLS backends close such connections). If missing, it is inherited
109461
+ * from the default TLS backend (TLS protocols) or returns NULL (plaintext);
109462
+ * it MUST match the `build_context` / `free_context` that own the context.
109319
109463
  */
109320
109464
  void *(*dup_context)(void *context);
109321
109465
  /**
@@ -110077,7 +110221,7 @@ FIO_SFUNC void fio___io_protocol_init(fio_io_protocol_s *pr, _Bool has_tls) {
110077
110221
  if (!pr->io_functions.free_context)
110078
110222
  pr->io_functions.free_context = io_fn.free_context;
110079
110223
  if (!pr->io_functions.dup_context)
110080
- pr->io_functions.dup_context = fio___io_func_default_dup_context;
110224
+ pr->io_functions.dup_context = io_fn.dup_context;
110081
110225
  if (!pr->io_functions.start)
110082
110226
  pr->io_functions.start = io_fn.start;
110083
110227
  if (!pr->io_functions.read)
@@ -112825,7 +112969,9 @@ static void fio___io_listen_on_data_task(void *io_, void *ignr_) {
112825
112969
  fio___io_listen_s *l = (fio___io_listen_s *)fio_io_udata(io);
112826
112970
  if (!fio_io_is_open(io)) /* closed while the accept task was queued */
112827
112971
  goto done;
112828
- fio_io_unsuspend(io);
112972
+ if ((FIO___IO_FLAG_UNSET(io, FIO___IO_FLAG_SUSPENDED) &
112973
+ FIO___IO_FLAG_SUSPENDED))
112974
+ fio___io_monitor_in(io);
112829
112975
  while (FIO_SOCK_FD_ISVALID(fd = fio_sock_accept(fio_io_fd(io), NULL, NULL))) {
112830
112976
  // FIO_LOG_DDEBUG2("(%d) accepted new connection with fd %d",
112831
112977
  // fio_io_pid(),
@@ -112967,6 +113113,7 @@ FIO_NOOP(struct fio_io_listen_args_s args) {
112967
113113
  return (fio_io_listener_s *)l;
112968
113114
  }
112969
113115
  fio_url_s url = fio_url_parse(args.url, url_alt.len);
113116
+ args.tls = fio_io_tls_from_url(args.tls, url);
112970
113117
  if (url.scheme.buf &&
112971
113118
  (url.scheme.len > 2 && url.scheme.len < 5 &&
112972
113119
  (url.scheme.buf[0] | (char)0x20) == 't' &&
@@ -112997,7 +113144,6 @@ FIO_NOOP(struct fio_io_listen_args_s args) {
112997
113144
  url = fio_url_parse(args.url, url_alt.len);
112998
113145
  }
112999
113146
 
113000
- args.tls = fio_io_tls_from_url(args.tls, url);
113001
113147
  fio___io_protocol_init_test(args.protocol, !!args.tls);
113002
113148
  built_tls = args.protocol->io_functions.build_context(args.tls, 0);
113003
113149
  if (args.tls && !built_tls) { /* TLS requested: never fall back to plain */
@@ -116617,6 +116763,18 @@ FIO_SFUNC void fio___openssl_alpn_client_dispatch(
116617
116763
  (fio_io_s *)SSL_get_ex_data(conn->ssl, 0));
116618
116764
  }
116619
116765
 
116766
+ /** Schedules `on_data` when input is buffered beyond the kernel socket (poll
116767
+ * won't report it): plaintext or records held by OpenSSL, or a complete TLS
116768
+ * record in `recv_buf`. A partial record waits for the socket. */
116769
+ FIO_SFUNC void fio___openssl_schedule_buffered(
116770
+ fio___openssl_connection_s *conn) {
116771
+ size_t avail = conn->recv_buf_len - conn->recv_buf_pos;
116772
+ const uint8_t *h = conn->recv_buf + conn->recv_buf_pos;
116773
+ if (SSL_has_pending(conn->ssl) ||
116774
+ (avail >= 5 && avail >= 5 + (((size_t)h[3] << 8) | (size_t)h[4])))
116775
+ fio_io_on_data_schedule((fio_io_s *)SSL_get_ex_data(conn->ssl, 0));
116776
+ }
116777
+
116620
116778
  /** Called to perform a non-blocking `read`, same as the system call.
116621
116779
  *
116622
116780
  * Custom BIO flow (one copy, same as BIO_new_socket):
@@ -116710,8 +116868,10 @@ FIO_SFUNC ssize_t fio___openssl_read(fio_socket_i fd,
116710
116868
  if (conn->enc_buf_len > conn->enc_buf_sent)
116711
116869
  fio___openssl_send_enc_buf(fd, conn);
116712
116870
 
116713
- if (r == 1)
116871
+ if (r == 1) {
116872
+ fio___openssl_schedule_buffered(conn); /* caller may not read again */
116714
116873
  return (ssize_t)readbytes;
116874
+ }
116715
116875
  if ((err = fio___openssl_failure(conn, r)))
116716
116876
  goto fatal;
116717
116877
  if (conn->rbio_starved ||
@@ -116744,6 +116904,10 @@ FIO_SFUNC int fio___openssl_flush(fio_socket_i fd, void *tls_ctx) {
116744
116904
  fio___openssl_connection_s *conn = (fio___openssl_connection_s *)tls_ctx;
116745
116905
  if (!conn)
116746
116906
  return 0;
116907
+ /* `on_ready` flushes before un-throttling: re-deliver input whose `on_data`
116908
+ * was skipped while throttled (mirrors the native TLS 1.3 flush). */
116909
+ if (conn->handshake_complete)
116910
+ fio___openssl_schedule_buffered(conn);
116747
116911
  if (conn->enc_buf_sent >= conn->enc_buf_len) {
116748
116912
  conn->enc_buf_len = 0;
116749
116913
  conn->enc_buf_sent = 0;
@@ -135234,6 +135398,8 @@ SFUNC fio_io_s *fio_http_connect FIO_NOOP(const char *url,
135234
135398
  fio_url_s u = (fio_url_s){0};
135235
135399
  if (url)
135236
135400
  u = fio_url_parse(url, FIO_STRLEN(url));
135401
+ const fio_url_tls_info_s tls_info = fio_url_is_tls(u);
135402
+ u.query = tls_info.query; /* TLS hints at the head / tail aren't sent */
135237
135403
  /* RFC 9110 §7.2: Host is the URL authority (host [":" port], no userinfo),
135238
135404
  * a slice of `url`: restore the `[IPv6]` brackets the parser strips, then
135239
135405
  * extend to the end of the port (which follows the host). */
@@ -135292,7 +135458,7 @@ SFUNC fio_io_s *fio_http_connect FIO_NOOP(const char *url,
135292
135458
  const int err = fio_string_write2(
135293
135459
  &origin,
135294
135460
  FIO_STRING_ALLOC_COPY,
135295
- FIO_STRING_WRITE_STR2("https", (size_t)(4 + fio_url_is_tls(u).tls)),
135461
+ FIO_STRING_WRITE_STR2("https", (size_t)(4 + tls_info.tls)),
135296
135462
  FIO_STRING_WRITE_STR2("://", 3U),
135297
135463
  FIO_STRING_WRITE_STR_INFO(authority));
135298
135464
  if (!err) /* the header map copies the value */