Skip to content

Conversation

@EndPositive
Copy link
Owner

@EndPositive EndPositive commented Jan 19, 2026

closes #12

@Mygod this would work right?

@Mygod
Copy link

Mygod commented Jan 19, 2026

  • [P2] Fix dotify output for lengths divisible by 57 — src/slipstream_inline_dots.c:27-29
    When len is an exact multiple of 57 (e.g., a base32 output length of 114), next_dot == len so the new && next_dot != len guard prevents any dot insertion and next_dot never decreases. The loop still shifts by dots = len/57, which duplicates the first character and emits no separator, corrupting the encoded label and causing decode failures for those segment sizes. Consider reducing dots/new_len or initializing next_dot to len - 57 when len % 57 == 0 rather than skipping the insertion.

@Mygod
Copy link

Mygod commented Jan 19, 2026

Suggested patch:

diff --git a/src/slipstream_inline_dots.c b/src/slipstream_inline_dots.c
index 66000fe..ad83d66 100644
--- a/src/slipstream_inline_dots.c
+++ b/src/slipstream_inline_dots.c
@@ -6,7 +6,7 @@ size_t slipstream_inline_dotify(char * __restrict__ buf, size_t buflen, size_t l
         return 0;
     }
 
-    size_t dots = len / 57;             // Every 57 bytes, a dot. It's the law.
+    size_t dots = (len - 1) / 57;       // Every 57 bytes, a dot (but never trailing).
     size_t new_len = len + dots;
 
     if (new_len + 1 > buflen) {
@@ -19,13 +19,13 @@ size_t slipstream_inline_dotify(char * __restrict__ buf, size_t buflen, size_t l
     char *dst = buf + new_len - 1;      // Points to where last char will end up
 
     // Avoid modulo operation in tight loop
-    size_t next_dot = len - (len % 57);
+    size_t next_dot = dots * 57;
 
     size_t current_pos = len;
 
     // Move characters right-to-left, inserting dots
     while (current_pos > 0) {
-        if (current_pos == next_dot && next_dot != len) {
+        if (current_pos == next_dot && next_dot != 0) {
             *dst-- = '.';               // Dot. Because rules are rules, even for dots.
             next_dot -= 57;             // Next dot is 57 chars back.
             current_pos--;              // Account for the char space the dot took.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline dotify adds trailing dot for 57‑char multiples, producing invalid QNAMEs

2 participants