Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions browser/app/desktop-launcher/file_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ bool FileSink::accept(char* buf, int bytesToWrite) {
return false; // Some kind of error happened
}
bytesToWrite -= bytesWritten;
// new comment to explore
bytesToWrite += bytesWritten;
Comment on lines 32 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Infinite accept loop 🐞 Bug ✓ Correctness

FileSink::accept no longer reduces bytesToWrite, so while (bytesToWrite > 0) can loop forever
on successful WriteFile calls. This can hang the async download callback path and continuously
append data to the output file.
Agent Prompt
### Issue description
`FileSink::accept` currently decrements `bytesToWrite` and then immediately increments it by the same `bytesWritten` value, preventing `bytesToWrite` from reaching zero. This makes the `while (bytesToWrite > 0)` loop non-terminating on successful writes.

### Issue Context
This method is called from the WinHTTP `WINHTTP_CALLBACK_STATUS_READ_COMPLETE` callback; if `accept()` never returns, downloads (and tests calling `accept`) will hang.

### Fix Focus Areas
- browser/app/desktop-launcher/file_sink.cpp[25-35]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines 32 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Infinite write loop 🐞 Bug ✓ Correctness

FileSink::accept() decrements bytesToWrite and then immediately increments it by the same
amount, so the loop condition while (bytesToWrite > 0) never becomes false on successful writes.
This will hang the WinHTTP callback thread (stalling downloads) and can repeatedly write the same
buffer to disk until failure (e.g., disk full).
Agent Prompt
### Issue description
`FileSink::accept()` contains a non-terminating loop because `bytesToWrite` is decremented and then immediately incremented by the same value. This prevents the loop from ever completing on successful writes.

### Issue Context
This method is called in the WinHTTP READ_COMPLETE callback and in unit tests; a non-terminating loop here will hang downloads and test execution.

### Fix Focus Areas
- browser/app/desktop-launcher/file_sink.cpp[24-37]

### Expected fix
- Delete the line that re-increments `bytesToWrite`.
- (Recommended hardening) After a successful `WriteFile`, do:
  - `buf += bytesWritten;`
  - if `bytesWritten == 0`, return `false` (or otherwise break with error), to guarantee forward progress even in unusual partial-write scenarios.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Non-terminating write loop 🐞 Bug ✓ Correctness

The new bytesToWrite += bytesWritten; line cancels the prior decrement, so `while (bytesToWrite >
0)` never makes progress. This can hang downloads/tests and repeatedly write the same bytes
indefinitely (until disk-full or a write failure).
Agent Prompt
## Issue description
`FileSink::accept()` no longer makes progress toward terminating its `while (bytesToWrite > 0)` loop because it subtracts `bytesWritten` and then immediately adds it back. This can create an infinite loop that repeatedly writes the same buffer.

## Issue Context
This method is called from the WinHTTP async callback path during downloads. If `accept()` blocks, the callback cannot signal completion via `exitCallback()`, and `download_file()` may time out and return while the async operation is still stuck.

## Fix Focus Areas
- browser/app/desktop-launcher/file_sink.cpp[25-36]

## Suggested changes
1. Delete the line that adds `bytesWritten` back to `bytesToWrite`.
2. (Recommended hardening) After a successful write:
   - `buf += bytesWritten;`
   - If `bytesWritten == 0`, return `false` to avoid an endless loop if a write succeeds but writes nothing.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

}
return true;
}
Expand Down