Skip to content

fix: overflow-safe detection, macOS 13 floor, Hashable model - #9

Open
eonist wants to merge 1 commit into
mainfrom
fix/safe-hardening-and-platform-floor
Open

eonist wants to merge 1 commit into
mainfrom
fix/safe-hardening-and-platform-floor

Conversation

@eonist

@eonist eonist commented Aug 28, 2026

Copy link
Copy Markdown
Member

Applies the subset of #8 that is either provably behaviour-preserving or test-only. Everything here was verified by building and running, not by inspection.

Deliberately excluded: the depth cap (#8 §1.1), .disableSmartOpts (§1.3), and everything in the "not low risk" tier. Those change output or architecture and deserve their own PRs.

What's in

Overflow trap in MarkdownDetector.detect (#8 §1.2)

Float(score * score * score) evaluated the multiplication in Int before converting, so it trapped at score >= 2_097_152.

  • Before: a ~5 MB heading-dense log exited with SIGTRAP (rc=133).
  • After: same input returns score 2097152, enable=true.
  • No behaviour change: I brute-forced the old and new gate across 9,003,000 (score, lines) combinations — zero decisions differ. The six boundary cases in mathematicalBoundaryContract still pass unchanged.

Platform floor: macOS 26 → macOS 13 (#8 §3.1)

Nothing in the package needed macOS 26. I rebuilt from a clean .build at each floor: macOS 14 and 13 both compile with zero errors and zero warnings, no code changes. macOS 12 fails, and only on Grid in MarkdownTableView.swift, which is macOS 13+ — so 13 is the true floor. This only widens support; behaviour on macOS 26 is identical.

Hashable / Equatable on the model (#8 §2.5)

MarkdownBlock, InlineNode, MarkdownTableModel (+ Cell, ColumnAlignment) get Hashable; MarkdownStyle (+ heading styles) gets Equatable. All synthesised — no hand-written conformances. This lets SwiftUI diff parsed content instead of re-rendering on every parent update, and is the prerequisite for the incremental-parse work in §2.5.

Worth noting explicitly: this is additive public API, so it's a permanent commitment. It's the conformance you'd want regardless, but it's the one change here that can't be quietly reverted later.

import Foundation in MarkdownDetector (#8 §1.5)

components(separatedBy:) was resolving only because Markdown re-exports Foundation. Pure hygiene, zero behaviour change.

Two regression tests (#8 §7)

New InlineTextViewTests:

  • onlyHTTPAndHTTPSLinksAreActionable — pins the allowlist DESIGN.md requires ("Treat input as untrusted"). Covers https, http, uppercase HTTPS, and asserts javascript:, file:, data:, runbot:, mailto:, and empty destinations stay inert while their label text remains visible. This was the one security-relevant behaviour in the package with no coverage.
  • nestedEmphasisUnionsPresentationIntents — pins the intent-union logic that keeps ***bold italic*** carrying both .stronglyEmphasized and .emphasized on one run. It's the subtlest code in the renderer and had no test.

Both pass against current behaviour — they pin what already works rather than demanding a fix. I mutation-tested the first one: removing the scheme check makes it fail with 5 issues, so it isn't vacuous.

This required relaxing InlineTextView.attributedString(for:) from private to internal. No public API impact.

Docs

  • README Development referenced --package-path Packages/MarkdownKit, a path that doesn't exist in this repo. Plain swift build / swift test work.
  • Requirements updated to macOS 13.
  • Added an Installation section (points at branch: "main" — there are no tags yet, see Package assessment: correctness, performance, platform reach, and packaging #8 §3.5).
  • .gitignore: .DS_Store, .swiftpm/, xcuserdata/, *.xcodeproj.

Verification

swift build            # 0 warnings, 0 errors
swift build -c release # 0 warnings, 0 errors
swift test             # 17 tests in 7 suites passed (was 15 in 6)

Closes part of #8. Remaining from that issue, in the order suggested there: the depth cap (§1.1, the one crash still open), .disableSmartOpts (§1.3), task-list checkboxes (§4), accessibility and text selection (§6), and the detector prefix cap plus detectAsync (§2.3).

🤖 Generated with Claude Code

Applies the changes from #8 that are either provably behaviour-preserving
or test-only.

Fixes an overflow trap in MarkdownDetector.detect. `score * score * score`
was evaluated in Int before the Float conversion, so it trapped once the
score reached 2_097_152 — verified reachable with a ~5 MB heading-dense
log, which previously exited with SIGTRAP and now returns normally.
Moving the gate arithmetic to Double changes no decision: a brute-force
comparison of the old and new gate over 9,003,000 (score, lines)
combinations found zero differences.

Lowers the platform floor from macOS 26 to macOS 13. Nothing in the
package required macOS 26; `Grid` in MarkdownTableView is the only
constraint below that, and it is macOS 13+. Builds clean at the new
floor with no code changes.

Adds Hashable to MarkdownBlock, InlineNode, and MarkdownTableModel, and
Equatable to MarkdownStyle. All conformances are synthesised. This lets
SwiftUI diff parsed content instead of re-rendering on every parent
update, and is a prerequisite for the streaming work in #8 §2.5.

Adds the missing `import Foundation` to MarkdownDetector, which used
components(separatedBy:) while relying on Markdown to re-export
Foundation.

Adds coverage for two previously untested behaviours: the http/https
link allowlist that DESIGN.md requires, and the presentation-intent
union that keeps `***bold italic***` carrying both intents on one run.
Both pass against current behaviour; removing the allowlist makes the
first fail with 5 issues, so it is not vacuous. Testing them required
relaxing InlineTextView.attributedString(for:) from private to internal.

README: corrects the Development commands, which referenced a
Packages/MarkdownKit path that does not exist in this repository, and
records the new platform requirement.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Greptile Summary

The PR fixes an integer-overflow trap in Markdown detection while preserving its decision thresholds, lowers the supported macOS floor to 13, and adds synthesized value conformances to parsed models and styles.

  • Computes detector density and cubic values in Double before multiplication.
  • Adds Hashable to normalized Markdown models and Equatable to style values.
  • Adds regression coverage for safe link activation and nested emphasis.
  • Updates package metadata, installation guidance, development commands, and ignored files.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete correctness or security defects identified in the changed code.

The overflow-safe arithmetic preserves the established detector gates, the new conformances cover complete value graphs, and the rendering tests pin existing security and formatting behavior without changing production output.

Important Files Changed

Filename Overview
Package.swift Lowers the declared macOS deployment target to 13; reviewed package source uses APIs compatible with that floor.
Sources/MarkdownKit/Detection/MarkdownDetector.swift Moves score arithmetic into Double, preventing the prior integer-overflow trap without changing established reachable gate decisions.
Sources/MarkdownKit/Model/MarkdownBlock.swift Adds structurally synthesized Hashable conformances across the recursive block and inline value graph.
Sources/MarkdownKit/Model/MarkdownTableModel.swift Adds synthesized hashing to the table, cell, and alignment models without changing table normalization.
Sources/MarkdownKit/Styling/MarkdownStyle.swift Adds synthesized equality across all stored style tokens and heading styles.
Sources/MarkdownKit/Rendering/MarkdownInlineRenderer.swift Widens one rendering helper to internal visibility solely to enable direct regression testing.
Tests/MarkdownKitTests/InlineTextViewTests.swift Adds focused tests for safe URL-scheme activation and preservation of nested presentation intents.
README.md Documents macOS 13 support, installation from the currently available branch, and corrected local build commands.

Reviews (1): Last reviewed commit: "fix: overflow-safe detection, macOS 13 f..." | Re-trigger Greptile

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.

1 participant