Skip to content

Commit 79dce79

Browse files
authored
Merge pull request from GHSA-7w47-3wg8-547c
fix for CVE-2024-35186 and CVE-2024-35197
2 parents 3c21741 + 1242151 commit 79dce79

File tree

97 files changed

+2268
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2268
-347
lines changed

Cargo.lock

Lines changed: 272 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,11 @@ pub use discover::discover;
8484

8585
#[cfg(all(feature = "async-client", feature = "blocking-client"))]
8686
compile_error!("Cannot set both 'blocking-client' and 'async-client' features as they are mutually exclusive");
87+
88+
fn is_dir_to_mode(is_dir: bool) -> gix::index::entry::Mode {
89+
if is_dir {
90+
gix::index::entry::Mode::DIR
91+
} else {
92+
gix::index::entry::Mode::FILE
93+
}
94+
}

gitoxide-core/src/repository/attributes/query.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) mod function {
1414
use gix::bstr::BStr;
1515

1616
use crate::{
17+
is_dir_to_mode,
1718
repository::{
1819
attributes::query::{attributes_cache, Options},
1920
PathsOrPatterns,
@@ -38,12 +39,12 @@ pub(crate) mod function {
3839
match input {
3940
PathsOrPatterns::Paths(paths) => {
4041
for path in paths {
41-
let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
42+
let mode = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
4243
.metadata()
4344
.ok()
44-
.map(|m| m.is_dir());
45+
.map(|m| is_dir_to_mode(m.is_dir()));
4546

46-
let entry = cache.at_entry(path.as_slice(), is_dir)?;
47+
let entry = cache.at_entry(path.as_slice(), mode)?;
4748
if !entry.matching_attributes(&mut matches) {
4849
continue;
4950
}
@@ -61,9 +62,9 @@ pub(crate) mod function {
6162
)?;
6263
let mut pathspec_matched_entry = false;
6364
if let Some(it) = pathspec.index_entries_with_paths(&index) {
64-
for (path, _entry) in it {
65+
for (path, entry) in it {
6566
pathspec_matched_entry = true;
66-
let entry = cache.at_entry(path, Some(false))?;
67+
let entry = cache.at_entry(path, entry.mode.into())?;
6768
if !entry.matching_attributes(&mut matches) {
6869
continue;
6970
}
@@ -87,10 +88,10 @@ pub(crate) mod function {
8788
let path = pattern.path();
8889
let entry = cache.at_entry(
8990
path,
90-
Some(
91+
Some(is_dir_to_mode(
9192
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
9293
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
93-
),
94+
)),
9495
)?;
9596
if !entry.matching_attributes(&mut matches) {
9697
continue;

gitoxide-core/src/repository/attributes/validate_baseline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub(crate) mod function {
192192
);
193193

194194
for (rela_path, baseline) in rx_base {
195-
let entry = cache.at_entry(rela_path.as_str(), Some(false))?;
195+
let entry = cache.at_entry(rela_path.as_str(), None)?;
196196
match baseline {
197197
Baseline::Attribute { assignments: expected } => {
198198
entry.matching_attributes(&mut matches);

gitoxide-core/src/repository/exclude.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{borrow::Cow, io};
33
use anyhow::bail;
44
use gix::bstr::BStr;
55

6-
use crate::{repository::PathsOrPatterns, OutputFormat};
6+
use crate::{is_dir_to_mode, repository::PathsOrPatterns, OutputFormat};
77

88
pub mod query {
99
use std::ffi::OsString;
@@ -44,11 +44,11 @@ pub fn query(
4444
match input {
4545
PathsOrPatterns::Paths(paths) => {
4646
for path in paths {
47-
let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
47+
let mode = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
4848
.metadata()
4949
.ok()
50-
.map(|m| m.is_dir());
51-
let entry = cache.at_entry(path.as_slice(), is_dir)?;
50+
.map(|m| is_dir_to_mode(m.is_dir()));
51+
let entry = cache.at_entry(path.as_slice(), mode)?;
5252
let match_ = entry
5353
.matching_exclude_pattern()
5454
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
@@ -66,9 +66,9 @@ pub fn query(
6666
)?;
6767

6868
if let Some(it) = pathspec.index_entries_with_paths(&index) {
69-
for (path, _entry) in it {
69+
for (path, entry) in it {
7070
pathspec_matched_something = true;
71-
let entry = cache.at_entry(path, Some(false))?;
71+
let entry = cache.at_entry(path, entry.mode.into())?;
7272
let match_ = entry
7373
.matching_exclude_pattern()
7474
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
@@ -92,10 +92,10 @@ pub fn query(
9292
let path = pattern.path();
9393
let entry = cache.at_entry(
9494
path,
95-
Some(
95+
Some(is_dir_to_mode(
9696
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
9797
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
98-
),
98+
)),
9999
)?;
100100
let match_ = entry
101101
.matching_exclude_pattern()

gitoxide-core/src/repository/index/entries.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) mod function {
3131
};
3232

3333
use crate::{
34+
is_dir_to_mode,
3435
repository::index::entries::{Attributes, Options},
3536
OutputFormat,
3637
};
@@ -174,7 +175,7 @@ pub(crate) mod function {
174175
}
175176
// The user doesn't want attributes, so we set the cache position on demand only
176177
None => cache
177-
.at_entry(rela_path, Some(is_dir))
178+
.at_entry(rela_path, Some(is_dir_to_mode(is_dir)))
178179
.ok()
179180
.map(|platform| platform.matching_attributes(out))
180181
.unwrap_or_default(),

gitoxide-core/src/repository/revision/resolve.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ pub(crate) mod function {
127127
}
128128
gix::object::Kind::Blob if cache.is_some() && spec.path_and_mode().is_some() => {
129129
let (path, mode) = spec.path_and_mode().expect("is present");
130-
let is_dir = Some(mode.is_tree());
131130
match cache.expect("is some") {
132131
(BlobFormat::Git, _) => unreachable!("no need for a cache when querying object db"),
133132
(BlobFormat::Worktree, cache) => {
134-
let platform = cache.attr_stack.at_entry(path, is_dir, &repo.objects)?;
133+
let platform = cache.attr_stack.at_entry(path, Some(mode.into()), &repo.objects)?;
135134
let object = id.object()?;
136135
let mut converted = cache.filter.worktree_filter.convert_to_worktree(
137136
&object.data,

gix-archive/tests/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod from_tree {
233233
noop_pipeline(),
234234
move |rela_path, mode, attrs| {
235235
cache
236-
.at_entry(rela_path, mode.is_tree().into(), &odb)
236+
.at_entry(rela_path, Some(mode.into()), &odb)
237237
.map(|entry| entry.matching_attributes(attrs))
238238
.map(|_| ())
239239
},

gix-diff/src/blob/platform.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,14 @@ impl Platform {
583583
if self.diff_cache.contains_key(storage) {
584584
return Ok(());
585585
}
586-
let entry = self
587-
.attr_stack
588-
.at_entry(rela_path, Some(false), objects)
589-
.map_err(|err| set_resource::Error::Attributes {
590-
source: err,
591-
kind,
592-
rela_path: rela_path.to_owned(),
593-
})?;
586+
let entry =
587+
self.attr_stack
588+
.at_entry(rela_path, None, objects)
589+
.map_err(|err| set_resource::Error::Attributes {
590+
source: err,
591+
kind,
592+
rela_path: rela_path.to_owned(),
593+
})?;
594594
let mut buf = Vec::new();
595595
let out = self.filter.convert_to_diffable(
596596
&id,

gix-diff/tests/blob/pipeline.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub(crate) mod convert_to_diffable {
507507
assert_eq!(out.data, Some(pipeline::Data::Binary { size: 11 }));
508508
assert_eq!(buf.len(), 0, "buffers are cleared even if we read them");
509509

510-
let platform = attributes.at_entry("c", Some(false), &gix_object::find::Never)?;
510+
let platform = attributes.at_entry("c", None, &gix_object::find::Never)?;
511511

512512
let id = db.insert("b");
513513
let out = filter.convert_to_diffable(
@@ -589,7 +589,7 @@ pub(crate) mod convert_to_diffable {
589589
let mut db = ObjectDb::default();
590590
let null = gix_hash::Kind::Sha1.null();
591591
let mut buf = Vec::new();
592-
let platform = attributes.at_entry("a", Some(false), &gix_object::find::Never)?;
592+
let platform = attributes.at_entry("a", None, &gix_object::find::Never)?;
593593
let worktree_modes = [
594594
pipeline::Mode::ToWorktreeAndBinaryToText,
595595
pipeline::Mode::ToGitUnlessBinaryToTextIsPresent,
@@ -672,7 +672,7 @@ pub(crate) mod convert_to_diffable {
672672
"no filter was applied in this mode, also when using the ODB"
673673
);
674674

675-
let platform = attributes.at_entry("missing", Some(false), &gix_object::find::Never)?;
675+
let platform = attributes.at_entry("missing", None, &gix_object::find::Never)?;
676676
for mode in all_modes {
677677
buf.push(1);
678678
let out = filter.convert_to_diffable(
@@ -731,7 +731,7 @@ pub(crate) mod convert_to_diffable {
731731
);
732732
}
733733

734-
let platform = attributes.at_entry("b", Some(false), &gix_object::find::Never)?;
734+
let platform = attributes.at_entry("b", None, &gix_object::find::Never)?;
735735
for mode in all_modes {
736736
buf.push(1);
737737
let out = filter.convert_to_diffable(
@@ -781,7 +781,7 @@ pub(crate) mod convert_to_diffable {
781781
assert_eq!(buf.len(), 0, "it's always cleared before any potential use");
782782
}
783783

784-
let platform = attributes.at_entry("c", Some(false), &gix_object::find::Never)?;
784+
let platform = attributes.at_entry("c", None, &gix_object::find::Never)?;
785785
for mode in worktree_modes {
786786
let out = filter.convert_to_diffable(
787787
&null,
@@ -827,7 +827,7 @@ pub(crate) mod convert_to_diffable {
827827
);
828828
}
829829

830-
let platform = attributes.at_entry("unset", Some(false), &gix_object::find::Never)?;
830+
let platform = attributes.at_entry("unset", None, &gix_object::find::Never)?;
831831
for mode in all_modes {
832832
let out = filter.convert_to_diffable(
833833
&null,
@@ -879,7 +879,7 @@ pub(crate) mod convert_to_diffable {
879879
assert_eq!(buf.len(), 0);
880880
}
881881

882-
let platform = attributes.at_entry("d", Some(false), &gix_object::find::Never)?;
882+
let platform = attributes.at_entry("d", None, &gix_object::find::Never)?;
883883
let id = db.insert("d-in-db");
884884
for mode in worktree_modes {
885885
let out = filter.convert_to_diffable(
@@ -923,7 +923,7 @@ pub(crate) mod convert_to_diffable {
923923
);
924924
}
925925

926-
let platform = attributes.at_entry("e-no-attr", Some(false), &gix_object::find::Never)?;
926+
let platform = attributes.at_entry("e-no-attr", None, &gix_object::find::Never)?;
927927
let out = filter.convert_to_diffable(
928928
&null,
929929
EntryKind::Blob,

0 commit comments

Comments
 (0)