TokenReader subrange bounds enforced inconsistently: peekToken/peekPreviousTokenKind/backtrackToMarker ignore embedded window
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Bắt đầu trong tsdoc/src/parser/TokenReader.ts bằng cách so sánh peekToken(), peekPreviousTokenKind() và backtrackToMarker() với các phương thức anh em có kiểm tra bảo vệ. Xem xét hành vi của embedded reader và các vị trí gọi NodeParser được nêu trong issue. Hoàn thành khi cả ba phương thức đều tuân theo cửa sổ [_readerStartIndex, _readerEndIndex) và hành vi được chọn khi kết thúc đầu vào được bao phủ bởi các bài kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
TokenReader respects its embedded subrange (_readerStartIndex/_readerEndIndex) in peekTokenKind()/peekTokenAfterKind()/peekTokenAfterAfterKind(), but three sibling methods ignore those bounds: peekToken() has no end guard at all, and peekPreviousTokenKind() / backtrackToMarker() compare against 0 / allow rewinding before the subrange start. This leaks outer tokens into embedded parses and can return undefined where Token is promised.
Location
- File:
tsdoc/src/parser/TokenReader.ts - Class:
TokenReader - Methods:
peekToken(): Token—return this.tokens[this._currentIndex];with no_readerEndIndexcheckpeekPreviousTokenKind()—if (this._currentIndex === 0)instead of=== this._readerStartIndexbacktrackToMarker(marker)— checksmarker > this._currentIndexbut notmarker < this._readerStartIndex
Contrast with the guarded siblings in the same file:
public peekTokenKind(): TokenKind {
if (this._currentIndex >= this._readerEndIndex) {
return TokenKind.EndOfInput;
}
...
}
Problem
peekToken()past end returnsundefined: return type claimsToken, but past_readerEndIndexthe index expression yieldsundefined. Callers doingpeekToken().range/peekToken().kindthen throwTypeError: Cannot read properties of undefinedinstead of getting a cleanEndOfInputsignal. Current internal hot paths inNodeParser.tshappen to callpeekTokenKind()first (e.g. block/inline tagbadCharacterpaths), which masks the hole, but the public API contract is broken for any external consumer or future internal use.peekPreviousTokenKind()leaks across embedded start: for an embedded reader starting at index N>0, calling it at the embedded start returnstokens[N-1].kind(outer context) instead ofEndOfInput.NodeParser._parseBlockTagand_parseFencedCodeswitch on this to decide start-of-input behavior (AtSignInWord,CodeFenceOpeningIndent); an embedded@or fence at the subrange start can therefore be misclassified using the token before the subrange.backtrackToMarker()can rewind before subrange start: nothing preventsmarker < _readerStartIndex, letting a laterreadToken()consume outer tokens that the embedded reader was explicitly scoped to exclude.
Trigger / Reproduction
Based on static analysis (no execution performed):
- Construct
new TokenReader(parserContext, embeddedSequence)whereembeddedSequence.startIndex > 0, advance to the embedded start, and callpeekPreviousTokenKind()— returns the outer predecessor kind instead ofEndOfInput. - Call
peekToken()when_currentIndex === _readerEndIndex— returnsundefinedinstead of signaling end (comparepeekTokenKind()returningEndOfInputin the same state). - Call
backtrackToMarker(outerMarker)withouterMarker < _readerStartIndexon an embedded reader — accepted, subsequent reads escape the subrange.
Note: this is a static-analysis finding; I did not execute a parser fixture.
Expected Behavior
All TokenReader accessors/mutators should honor the same [ _readerStartIndex, _readerEndIndex ) window: peekToken() should signal end (or throw a clear parser-bug error like readToken() does) instead of returning undefined; peekPreviousTokenKind() should return EndOfInput at the subrange start; backtrackToMarker() should reject markers below the subrange start.
Actual Behavior
Subrange bounds are enforced inconsistently, so embedded parses can observe outer tokens and end-of-input handling differs by method.
Impact
- Potential spurious
AtSignInWord/ fence-indent errors for embedded constructs starting at a subrange boundary. undefined-tokenTypeErrors for API consumers usingpeekToken()at end, bypassing the cleanEndOfInputprotocol every sibling method follows.
Suggested Direction
- Mirror the existing
peekTokenKind()guard inpeekToken()(return theEndOfInputtoken or throw a parser-bug error — maintainer's choice, but document it), change thepeekPreviousTokenKind()zero-check to_readerStartIndex, and add amarker < _readerStartIndexrejection inbacktrackToMarker(). No grammar changes needed.
Evidence
- Source via API:
tsdoc/src/parser/TokenReader.tsshows guardedpeekTokenKind/peekTokenAfterKind/peekTokenAfterAfterKindvs unguardedpeekToken/peekPreviousTokenKind/backtrackToMarker;tsdoc/src/parser/NodeParser.tsshowspeekPreviousTokenKindgatingAtSignInWord/CodeFenceOpeningIndentand embeddedTokenReaderconstruction for scoped parses. - Duplicate check: issue search for
peekToken TokenReader boundsreturnstotal_count: 0, and open issues contain no TokenReader-boundary report — no apparent duplicate. This is a non-security correctness finding, so Microsoft's private-security-disclosure requirement does not apply.
Classification
- FACT: three
TokenReadermethods ignore the subrange window that three sibling methods enforce (verified in source via API). - INFERENCE: embedded parses can observe out-of-range tokens; end-of-input
peekToken()yieldsundefined. - HYPOTHESIS: aligning all methods on the same window fixes the misclassification/TypeError risk with no grammar change.
- Ngôn ngữ chính
- TypeScript
- Star
- 5k
- Fork
- 162
- Merge trung bình
- 17 giờ 4 phút
- Pull request đã merge (30 ngày)
- 7
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/tsdoc
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
microsoft/tsdoc#470 · 2 bình luận · 6 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
microsoft/tsdoc#450 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/tsdoc
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
rohitg00/agentmemory#1428 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
boxlite-ai/boxlite#1729 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Detect Deno tasks from deno.jsonĐang mởdetectors enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
SM260845/readme-gen#1 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
angular/angularfire#3774 ·
Maintainer thường phản hồi trong vòng 2 ngày