Skip to content

A default :80 written with leading zeros mangles the host on link rewrite#632

Merged
xroche merged 1 commit into
masterfrom
fix-627-port80-strip
Jul 18, 2026
Merged

A default :80 written with leading zeros mangles the host on link rewrite#632
xroche merged 1 commit into
masterfrom
fix-627-port80-strip

Conversation

@xroche

@xroche xroche commented Jul 18, 2026

Copy link
Copy Markdown
Owner

A default :80 written with leading zeros (:080, :0080) mangled the host when HTTrack rewrites a crawled link. The port-strip step read the port digit by digit, then when the value evaluated to 80 it skipped a hardcoded three characters (":80") instead of the length it had actually matched. So http://127.0.0.1:080/x turned into http://127.0.0.10/x, and :0080 into http://127.0.0.180/x. The same accumulator had no range check, so a value that wraps to 80 as a 32-bit int (:4294967376, the #614 shape) took the same path.

The block now lives in hts_strip_default_port(), which parses the matched digits through the range-checked hts_parse_url_port() helper (from #620) and strips the whole matched length. :080 still parses as a legitimate 80 and is dropped in full; a wrapped or out-of-range value is left untouched. A "stripport" engine self-test drives the corrupting inputs plus an :0081 control.

Closes #627

The link-rewrite step that drops a redundant :80 read the port with a
hand-rolled digit accumulator, then skipped a hardcoded 3 chars (":80")
when the value equaled 80. Any longer spelling that still evaluates to
80 lost only its first 3 chars and glued the rest onto the host:
http://127.0.0.1:080/x became 127.0.0.10/x, :0080 became 127.0.0.180.
The accumulator was also unchecked, so :4294967376 wrapped to 80 and
took the same path (#614 shape).

Extract the strip into hts_strip_default_port() and parse the matched
digits with the range-checked hts_parse_url_port(): a wrapped or
out-of-range value no longer aliases 80, and a genuine default is
dropped by its full matched length instead of 3. Covered by the
"stripport" engine self-test (tests/66_engine-port80-strip.test).

Closes #627

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche merged commit 8a8fd7f into master Jul 18, 2026
37 of 38 checks passed
xroche added a commit that referenced this pull request Jul 18, 2026
Resolve tests/Makefile.am: keep both 66_engine-port80-strip (from #632) and
67_engine-delayed-truncate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
xroche added a commit that referenced this pull request Jul 18, 2026
Resolve tests/Makefile.am: keep 66_engine-port80-strip (#632) alongside this
branch's test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
xroche added a commit that referenced this pull request Jul 18, 2026
Resolve tests/Makefile.am: keep 66_engine-port80-strip (#632) alongside this
branch's test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
xroche added a commit that referenced this pull request Jul 18, 2026
Resolve tests/Makefile.am: keep 66_engine-port80-strip (#632) alongside this
branch's test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
xroche added a commit that referenced this pull request Jul 18, 2026
The test matched engine output with `echo "$out" | grep -q PATTERN`. Under
`set -o pipefail`, grep -q exits the moment it matches, so echo takes a SIGPIPE
writing the rest and the pipeline reports failure even though the pattern was
found. The `|| { echo FAIL; exit 1; }` guard then fired on a passing case,
turning it into an intermittent, output-size-dependent failure (seen on the
Debian buildd leg of #632).

Match with here-strings instead, dropping the pipe and the race entirely.

Signed-off-by: Xavier Roche <roche@httrack.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
xroche added a commit that referenced this pull request Jul 18, 2026
Resolve tests/Makefile.am: keep 66 (#632), 67 (#633) and this branch's 69.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
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.

A port that evaluates to 80 without being spelled ":80" corrupts the host

1 participant