@@ -27,8 +27,9 @@ const MAX_LINKS_PER_DOCUMENT = 2000;
2727// Only resolve to source locations the language server is expected to return.
2828const ALLOWED_SOURCE_SCHEMES = new Set < string > ( [ "file" , "jdt" ] ) ;
2929
30- // Cap how much of the clipboard we scan when deciding whether to prefill (ReDoS hygiene).
31- const MAX_CLIPBOARD_SCAN_LENGTH = 20000 ;
30+ // Bound both stack-trace detection and scratch-document prefill so a large clipboard cannot create
31+ // an expensive untitled document (and keeps the detection regex input bounded).
32+ const MAX_CLIPBOARD_PREFILL_LENGTH = 20000 ;
3233
3334interface IStackFrameLinkArgs {
3435 stackTrace : string ;
@@ -131,15 +132,16 @@ async function analyzeStackTrace(): Promise<void> {
131132 // The command itself is auto-instrumented via instrumentOperationAsVsCodeCommand, so no
132133 // manual telemetry is needed here to track invocations.
133134 const clipboard = await env . clipboard . readText ( ) ;
134- const looksLikeTrace = parseJavaStackFrame ( clipboard . slice ( 0 , MAX_CLIPBOARD_SCAN_LENGTH ) ) !== undefined ;
135- const content = looksLikeTrace ? clipboard : "" ;
135+ const clipboardContent = clipboard . slice ( 0 , MAX_CLIPBOARD_PREFILL_LENGTH ) ;
136+ const looksLikeTrace = parseJavaStackFrame ( clipboardContent ) !== undefined ;
137+ const content = looksLikeTrace ? clipboardContent : "" ;
136138 const document = await workspace . openTextDocument ( { language : "log" , content } ) ;
137139 await window . showTextDocument ( document ) ;
138140}
139141
140142export function registerStackTraceLinkProvider ( context : ExtensionContext ) : void {
141- // The commands are always available: the palette command must not depend on server
142- // readiness, and the click handler is only ever reached from links the provider creates .
143+ // Register handlers immediately for programmatic invocations and existing command links.
144+ // Palette visibility and creation of new links are gated on language-server readiness elsewhere .
143145 context . subscriptions . push (
144146 commands . registerCommand ( NAVIGATE_TO_STACK_FRAME_COMMAND , navigateToStackFrame ) ,
145147 instrumentOperationAsVsCodeCommand ( ANALYZE_STACK_TRACE_COMMAND , analyzeStackTrace ) ,
0 commit comments