add check sort

This commit is contained in:
Jean-Marie Mineau 2023-08-25 11:30:09 +02:00
parent d5b8222491
commit 736c4611ac
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
3 changed files with 16 additions and 1 deletions

View file

@ -56,6 +56,18 @@ impl Serializable for EncodedAnnotation {
for _ in 0..size {
elements.push(AnnotationElement::deserialize(input)?);
}
if !elements.is_empty() {
let mut idx_0 = elements[0].name_idx;
for idx_1 in elements.iter().map(|elt| elt.name_idx).skip(1) {
if idx_0 > idx_1 {
// TODO: use proper logging
println!(
"Waring while deserializing EncodedAnnotation: element must be sorted in increasing order by string_id index, found {idx_0:?} before {idx_1:?}"
);
}
idx_0 = idx_1;
}
}
Ok(Self { type_idx, elements })
}

View file

@ -41,3 +41,5 @@ impl Serializable for EncodedArray {
self.size_field().size() + self.values.iter().map(|val| val.size()).sum::<usize>()
}
}
// TODO: add tests

View file

@ -3,7 +3,6 @@
use crate::{EncodedAnnotation, EncodedArray, Error, ReadSeek, Result, Serializable};
use std::io::Write;
// TODO: TESTS!!!
/// An encoded value of arbitrary hierachically structured data:
/// https://source.android.com/docs/core/runtime/dex-format#encoding
#[derive(Debug, Clone)]
@ -669,3 +668,5 @@ impl Serializable for Idx {
}
}
}
// TODO: TESTS!!!