Skip to content

Commit f2c2b3d

Browse files
authored
uapi16: fill in nothing from more than MAX_CONTENTS contents objects
A reader refuses the record of a file object with more than MAX_CONTENTS contents objects: manifest object 1: more than 256 contents entries and so does a writer. But set_contents() still fills in from them: 257 contents objects with the file "a" and the original size 5 give each of them the encoded size 5 and the object the size 5, all marked as filled in. With 256 of them a reader takes the record, and set_contents() gives the object the reader reads. Nothing follows from contents objects a reader doesn't take. So with more than MAX_CONTENTS of them set_contents() fills in nothing at all, neither for the object nor for any of them, and doesn't check them either. Of the 3168800 file objects of the sweep, 4000 have 256 or 257 contents objects. Before this change 42 of them didn't agree with a reader. Now none of the file objects of the sweep disagrees, and where a reader takes the record nothing changes. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
1 parent 84ee0b7 commit f2c2b3d

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎src/uapi16/decode.rs‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,15 @@ impl FileObject {
471471
/// [`ContentsObject::check_values`], and whose fields agree with each
472472
/// other. Where one of them does not, nothing is filled in for the
473473
/// object either, as a reader refuses its record and a writer refuses
474-
/// the object.
474+
/// the object. Where there are more than [`MAX_CONTENTS`] of them,
475+
/// nothing is filled in at all, neither for the object nor for any of
476+
/// them.
475477
pub(crate) fn fill_in_from_contents(&mut self) {
478+
// A reader refuses the record of an object with more than
479+
// MAX_CONTENTS contents objects, and nothing follows from them.
480+
if self.contents.len() > MAX_CONTENTS {
481+
return;
482+
}
476483
// The object is in no record, and what is wrong with it is not
477484
// shown, so the number of the record does not matter.
478485
let subject = Subject::new(self, ROOT_RECORD);
@@ -3146,6 +3153,30 @@ mod tests {
31463153
assert!(object.filled_in().is_empty(), "{}", record);
31473154
assert_eq!(object.contents(), [contents], "{}", record);
31483155
}
3156+
// As many contents objects as a reader takes, and one more, for
3157+
// which nothing is filled in at all.
3158+
let one = ContentsObject {
3159+
original_size: Some(5),
3160+
..file()
3161+
};
3162+
let many = |n: usize| {
3163+
let record = vec![r#"{"file":"a","originalSize":5}"#; n].join(",");
3164+
(
3165+
format!(r#"{{"name":"x","contents":[{}]}}"#, record),
3166+
set(None, None, vec![one.clone(); n]),
3167+
)
3168+
};
3169+
let (record, object) = many(MAX_CONTENTS);
3170+
assert_eq!(object.size(), Some(5));
3171+
assert_eq!(object, self::object(&record));
3172+
let (record, object) = many(MAX_CONTENTS + 1);
3173+
assert_eq!(
3174+
refused(&record).to_string(),
3175+
"manifest object 1: more than 256 contents entries"
3176+
);
3177+
assert_eq!((object.size(), object.sha256()), (None, None));
3178+
assert!(object.filled_in().is_empty());
3179+
assert!(object.contents().iter().all(|contents| *contents == one));
31493180
}
31503181

31513182
#[test]

‎src/uapi16/object.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,8 @@ impl FileObject {
18261826
/// reader filled in that no longer follows is dropped, and what the
18271827
/// object states stays. A writer refuses an object whose fields
18281828
/// contradict each other or that has such a value, and more than
1829-
/// [`MAX_CONTENTS`] contents objects.
1829+
/// [`MAX_CONTENTS`] contents objects, for which nothing is filled in at
1830+
/// all.
18301831
///
18311832
/// [`MAX_CONTENTS`]: crate::MAX_CONTENTS
18321833
pub fn set_contents(&mut self, contents: Vec<ContentsObject>) {

0 commit comments

Comments
 (0)