fix(mcp): replace .db-targeting stat() with cbm_file_size on Windows (> 2 GB)#579
Open
BombaxCeiba wants to merge 1 commit into
Open
fix(mcp): replace .db-targeting stat() with cbm_file_size on Windows (> 2 GB)#579BombaxCeiba wants to merge 1 commit into
.db-targeting stat() with cbm_file_size on Windows (> 2 GB)#579BombaxCeiba wants to merge 1 commit into
Conversation
…(>2GB) On Windows struct stat::st_size is a 32-bit long, so any .db larger than 2 GB makes stat() fail with EOVERFLOW. Three call sites in src/mcp/mcp.c checked .db files this way and silently mishandled the > 2 GB case: list_projects dropped the project from the UI list, maybe_auto_index re-indexed it on every server start, and try_artifact_bootstrap re-imported it from the artifact. Replace all three with the existing cbm_file_size (platform.c), which is wide-char + 64-bit clean on Windows (GetFileAttributesExW) and returns int64_t on both platforms, so the size never rides through the 32-bit st_size. Signed-off-by: Dusk_NM02 <dusk.11th@outlook.com>
6s9s2k6p5y-beep
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #578
Summary
The reported bug: on Windows,
list_projectsdrops any.db> 2 GB from theUI project list. Root cause is a bare
stat(), whosest_sizeis a 32-bitlongon Windows — for files > 2 GB the call fails withEOVERFLOWand theentry is silently skipped.
While triaging that, two more
.db-targetingstat()sites inmcp.cturnedout to share the exact same > 2 GB bug, so this PR fixes all three in one go:
list_projects— drops the project from the UI list (the reported symptom).maybe_auto_index— mis-detects the.dbas absent and re-indexes theproject on every server start (when
auto_indexis on).try_artifact_bootstrap— mis-detects it as absent and wastes an artifactimport (immediately overwritten by the ensuing pipeline rebuild).
All three now use the codebase's existing
cbm_file_sizehelper (alreadywide-char + 64-bit clean, already used by the UI layer) instead of
stat().Root cause
struct stat::st_sizeis a 32-bitlongon Windows (MinGW / MSVC), sostat()on a > 2 GB file fails withEOVERFLOW(returns -1). Each of thethree sites treated that -1 as "file missing" or "skip", so a valid > 2 GB
.dbwas silently dropped / re-indexed / re-imported.(
build_project_json_entryalso read(int64_t)st->st_size— moot on Windowssince the entry never reached it, and would truncate anyway.)
The fix
Single file changed:
src/mcp/mcp.c(+7 / −9). No new function, no newinclude. Each site swaps
stat()for the existingcbm_file_size()(declaredin
foundation/platform.h, whichmcp.calready includes):list_projects/build_project_json_entry— size is now taken asint64_tfromcbm_file_size(full_path)(was(int64_t)st->st_size); theskip guard becomes
if (size_bytes < 0) continue;.try_artifact_bootstrap—stat(db_buf) != 0(missing) →cbm_file_size(db_buf) < 0.maybe_auto_index—stat(db_check) == 0(present) →cbm_file_size(db_check) >= 0.cbm_file_sizeis wide-char + 64-bit clean on Windows (GetFileAttributesExWcbm_utf8_to_wide, composingnFileSizeHigh/nFileSizeLowintoint64_t)and uses plain
stat()on POSIX (off_tis already 64-bit under LFS). Itreturns
CBM_NOT_FOUND(-1) on failure, so the existing missing-file logicis preserved at every site.
Relation to prior work (#386 / #394)
Distinct from the merged #386 (
fix(windows): use wide-char API for non-ASCII path support), despite sharing thestatsurface:stat→_wstat64). Its changes (discover.c,compat_fs.c,platform.c,win_utf8.h) do not touchmcp.c, so these sites kept their barestat().struct stat::st_sizeisa 32-bit
longon Windows, so a > 2 GB.dbmakesstat()fail withEOVERFLOW. Orthogonal to path encoding.This PR adds no new helper. It reuses
cbm_file_size, which already existedon
main(introduced in94a9a92, well before #386) and which #386 happened toupgrade to wide-char safety on the Windows side. A naive migration to #386's
wide_statwould not have fixed this:wide_statwrites the_stat64result back into a
struct stat, wherest_sizestays 32-bit on Windows, sothe size would truncate instead of failing.
cbm_file_sizereturnsint64_tdirectly, which is what actually closes the hole.
Not a duplicate of anything under #394 (Windows cluster) — none of its 8
sub-issues cover the large-file /
st_size-overflow class.Verification
cbm_file_sizereturns the size asint64_ton both platforms — on Windowsvia
GetFileAttributesExW(no 32-bitst_sizein play, soEOVERFLOWisimpossible), on POSIX via
stat()(identical to the old path). The > 2 GB casecan no longer be dropped / re-indexed / re-imported, and POSIX behaviour is
unchanged. CI runs the full test suite on Windows and POSIX on PR open.