Skip to content

fix(gix): use Git for .gitmodules lines that Git reject karta hai - #2345

Merged
Byron merged 2 commits into
gitpython-developers:mainfrom
Keerthana-64:gix-gitmodules-rejected-lines
Nov 14, 2026
Merged

Byron merged 2 commits into
gitpython-developers:mainfrom
Keerthana-64:gix-gitmodules-rejected-lines

Conversation

@Keerthana-64

Copy link
Copy Markdown
Contributor

gix backend mein _backend.submodule_config, GixPython ke ModulesFile.from_bytes ka use karke .gitmodules file ko read karta hai. Yeh parser un lines ko bhi accept kar leta hai jinhe Git bad config line ke saath reject karta hai, aur phir bhi unse settings return karta hai.

Example ke liye, url = ../good ke baad agar ek line x url = ../evil ho, toh parser ise implicit x plus url = ../evil ke roop mein read karta hai. Is wajah se repo.submodules ../evil report karta hai aur Submodule.update(init=True) us URL se clone kar leta hai, jabki git submodule update --init is invalid configuration par ruk jata hai.

git fsck --strict sirf gitmodulesParse warning deta hai, aur CLI backend ParsingError raise karta hai. GixPython mein strict mode available nahi hai, isliye adapter ab Git par fallback karta hai, jab tak har line inmein se ek na ho: blank line, comment, ek bare submodule header, ya ek single key = [value] setting.

Yeh guard sirf fallback select karta hai aur kabhi bhi khud values produce nahi karta. Is mismatch ko doc/gix-backend.md mein GIX-35 ke roop mein document kiya gaya hai.

Motivation:

Yeh issue is baat ke review ke dauran saamne aaya ki native gix adapters untrusted repository content ko kaise handle karte hain, aur same input par har adapter ko Git ke saath compare kiya gaya.

test_submodule_configuration_rejects_lines_git_rejects test, change se pehle gix par teeno fixture scenarios mein fail hota tha, aur change ke baad dono backends par pass hota hai.

git config --list ke against chalaye gaye differential fuzzer ne change se pehle rejected files mein native values find ki thi, lekin change ke baad 13,000 inputs mein aisi koi value nahi mili. Jahan Git file accept karta hai, wahan values mein koi difference nahi mila.

Full test suite dono backends par pass hoti hai (gix par native submodule reads abhi bhi 943 calls serve karti hain). Iske alawa ruff, mypy aur shellcheck bhi pass hote hain.

Testing macOS par Git 2.54.0 aur GixPython 0.3.0 ke saath ki gayi hai.

<!-- agent: Claude -->

On the Gix backend, `_backend.submodule_config()` reads `.gitmodules`
with GixPython's `ModulesFile.from_bytes()` for `Repo.submodules`,
`Submodule.iter_items()` and the cached `path`, `url` and `branch`
fields. GixPython 0.3.0 accepts lines that Git rejects with
`bad config line` and still returns settings from them. A line holding
more than one name is read as several settings: after
`url = ../good`, the line `x url = ../evil` is read as an implicit `x`
plus `url = ../evil`, and `[submodule "module"] x url = ../evil` does
the same on a header line. `br#anch = main` is read as an implicit `br`
followed by a comment.

`.gitmodules` is untrusted repository content. For such a file,
`git submodule update --init` stops with `fatal: bad config line`,
`git fsck --strict` only warns `gitmodulesParse` and exits 0, and the
CLI backend raises `configparser.ParsingError`. The Gix backend instead
listed the submodule with `../evil`, a URL Git never reads, and
`Submodule.update(init=True)` cloned from it.

GixPython has no strict parsing mode, so the adapter now selects the CLI
path unless every line is blank, a comment, a bare `[submodule "..."]`
header or a single `key` or `key = value` setting. Git then reports the
error exactly as on the CLI backend. The guard only chooses the
fallback and produces no values. Continued values and settings on header
lines also go to Git, which keeps the guard simple at the cost of one
CLI call for those uncommon files. The mismatch is recorded as GIX-35 in
`doc/gix-backend.md`; this guard does not close it.

Validation on macOS arm64 with CPython 3.13.17, Git 2.54.0 and
GixPython 0.3.0:

- `test_submodule_configuration_rejects_lines_git_rejects`, using the
  new `submodule-rejected-lines.sh` fixture, fails for all three
  scenarios on the Gix backend before the change and passes on both
  backends after it.
- A differential fuzzer comparing the adapter with
  `git config --file .gitmodules --list` found rejected files with
  native values within the first 3,000 mutated inputs before the change,
  and none in 13,000 after it. Where Git accepts a file, it found no
  value differences in 7,500 inputs.
- Full suite: 2103 passed, 155 skipped, 1 xfailed on the CLI backend;
  2206 passed, 52 skipped, 1 xfailed on the Gix backend, where native
  submodule reads still serve 943 calls and the new fallback serves only
  the 6 calls from the new test.
- Ruff check and format, mypy, shellcheck and `git diff --check` pass.

Agent-Model: claude-opus-5-5
Byron pushed a commit to GitoxideLabs/gitoxide that referenced this pull request Nov 14, 2026
GitPython's native gix backend exposed submodule settings from malformed
`.gitmodules` files that Git refuses to read. In particular, a line such
as `x url = ../evil` could override an earlier URL and make a consumer
clone from that location. This work was motivated by
gitpython-developers/GitPython#2345.

Require an implicit value to end at EOF, LF, or CRLF after the existing
space/tab handling. Extra names, attached or spaced comments, and section
headers are errors unless the key has an explicit `=`. Keep valid
header-line settings, implicit booleans, quoting, and continuations.

Add a read-only, 25-case baseline generated by `git config --file -
--list`, including winning URLs for accepted files. Compare the public
event and file parsers, including filtered events, and add a public
`gix-submodule::File::from_bytes()` regression. Both new regressions failed
before the fix. Update the old permissive comment expectation, diagnostics,
and malformed fuzz fixtures while retaining the memory budget check.

Commit review found that `SectionMut::push_with_comment()` produced the
same invalid syntax for implicit values, including CLI overrides. Put
those comments on the following line, preserving implicit true, and add
LF/CRLF serialization round trips plus a CLI override round trip.

CI's `housekeeping@linux-x86_64` mode check caught the new fixture's
non-executable shebang. Mark the script executable and verify it with
`cargo run --profile qa --locked -p internal-tools --no-default-features
--bin qa -- exec mode`.

Reference: Git 2.54.0 (Apple Git-157); local Git source
`6de20f6092dcf9bdb1c8efe03db4b70c82b423dd`, `config.c:get_value()` and
`t/t1300-config.sh`'s same-line section-setting test. Git also rejects both
affected fuzz fixtures with exit 128.

Validation:
- `cargo test -p gix-config -p gix-submodule --all-features --tests`
  with `CI=true GIX_TEST_IGNORE_ARCHIVES=1`: 415 tests passed.
- Doctests with `gix-config/sha1,gix-config/sha256,gix-config/serde`:
  31 passed (the optional `document-features` docs require nightly).
- `cargo test --locked -p gix --test gix submodule::`: 40 passed.
- `cargo test --locked -p gix --test gix config::`: 142 passed.
- `cargo clippy -p gix-config -p gix-submodule --all-features --all-targets
  -- -D warnings`, `cargo fmt --all --check`, `git diff --check`, and
  `shellcheck gix-config/tests/fixtures/make_parse_baseline.sh` passed.
Byron added a commit to GitoxideLabs/gitoxide that referenced this pull request Nov 14, 2026
This removes a long-standing 'leniency' that I thought was a feature.
But probably it can always be turned into something surprising that
better doesn't exist.

<!-- agent -->
GitPython's native gix backend exposed submodule settings from malformed
`.gitmodules` files that Git refuses to read. In particular, a line such
as `x url = ../evil` could override an earlier URL and make a consumer
clone from that location. This work was motivated by
gitpython-developers/GitPython#2345.

Require an implicit value to end at EOF, LF, or CRLF after the existing
space/tab handling. Extra names, attached or spaced comments, and section
headers are errors unless the key has an explicit `=`. Keep valid
header-line settings, implicit booleans, quoting, and continuations.

Add a read-only, 25-case baseline generated by `git config --file -
--list`, including winning URLs for accepted files. Compare the public
event and file parsers, including filtered events, and add a public
`gix-submodule::File::from_bytes()` regression. Both new regressions failed
before the fix. Update the old permissive comment expectation, diagnostics,
and malformed fuzz fixtures while retaining the memory budget check.

Reference: Git 2.54.0 (Apple Git-157); local Git source
`6de20f6092dcf9bdb1c8efe03db4b70c82b423dd`, `config.c:get_value()` and
`t/t1300-config.sh`'s same-line section-setting test. Git also rejects both
affected fuzz fixtures with exit 128.

Assisted-by: GPT 6.1 Sol
Co-authored-by: GPT 6.1 Sol <codex@openai.com>
Keept the note about the Gix shortcoming without protecting against it.
Plan is to have this fixed before release.
@Byron

Byron commented Nov 14, 2026

Copy link
Copy Markdown
Member

Thanks!
I have kept only the note about the gix shortcoming, as it will be fixed before a release.

@Byron
Byron merged commit 40a9a27 into gitpython-developers:main Nov 14, 2026
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants