media-converter: Don't panic on unknown tags for read-only DBs

CW-Bug-Id: #19516
This commit is contained in:
Andrew Eikum 2021-12-03 09:08:02 -06:00
parent ec7e70b0c0
commit 8f5a92e619
3 changed files with 11 additions and 5 deletions

View File

@ -198,7 +198,7 @@ static DUMP_FOZDB: Lazy<Mutex<Option<fossilize::StreamArchive>>> = Lazy::new(||
return Mutex::new(None); return Mutex::new(None);
} }
match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(true), AUDIOCONV_FOZ_NUM_TAGS) { match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(true), false /* read-only? */, AUDIOCONV_FOZ_NUM_TAGS) {
Ok(newdb) => Mutex::new(Some(newdb)), Ok(newdb) => Mutex::new(Some(newdb)),
Err(_) => Mutex::new(None), Err(_) => Mutex::new(None),
} }
@ -454,7 +454,7 @@ impl AudioConvState {
gst_loggable_error!(CAT, "MEDIACONV_AUDIO_TRANSCODED_FILE is not set!") gst_loggable_error!(CAT, "MEDIACONV_AUDIO_TRANSCODED_FILE is not set!")
})?; })?;
let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), AUDIOCONV_FOZ_NUM_TAGS) { let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), true /* read-only? */, AUDIOCONV_FOZ_NUM_TAGS) {
Ok(s) => Some(s), Ok(s) => Some(s),
Err(_) => None, Err(_) => None,
}; };

View File

@ -197,6 +197,7 @@ impl PayloadEntry {
pub struct StreamArchive { pub struct StreamArchive {
file: fs::File, file: fs::File,
read_only: bool,
seen_blobs: Vec<HashMap<FossilizeHash, PayloadEntry>>, seen_blobs: Vec<HashMap<FossilizeHash, PayloadEntry>>,
@ -210,7 +211,7 @@ pub enum CRCCheck {
impl StreamArchive { impl StreamArchive {
pub fn new<P: AsRef<std::path::Path>>(filename: P, fileopts: &OpenOptions, num_tags: usize) -> Result<Self, Error> { pub fn new<P: AsRef<std::path::Path>>(filename: P, fileopts: &OpenOptions, read_only: bool, num_tags: usize) -> Result<Self, Error> {
let file = fileopts.open(filename)?; let file = fileopts.open(filename)?;
@ -221,6 +222,7 @@ impl StreamArchive {
let mut ret = Self { let mut ret = Self {
file, file,
read_only,
seen_blobs, seen_blobs,
write_pos: 0, write_pos: 0,
}; };
@ -269,6 +271,10 @@ impl StreamArchive {
match res { match res {
Ok(p) => { Ok(p) => {
self.write_pos = p; self.write_pos = p;
if tag >= self.seen_blobs.len() && self.read_only {
/* ignore unknown tags for read-only DBs, otherwise panic */
continue;
}
self.seen_blobs[tag].insert(hash, payload_entry); self.seen_blobs[tag].insert(hash, payload_entry);
}, },

View File

@ -124,7 +124,7 @@ static DUMP_FOZDB: Lazy<Mutex<Option<fossilize::StreamArchive>>> = Lazy::new(||
return Mutex::new(None); return Mutex::new(None);
} }
match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(true), VIDEOCONV_FOZ_NUM_TAGS) { match fossilize::StreamArchive::new(&dump_file_path, OpenOptions::new().write(true).read(true).create(true), false /* read-only? */, VIDEOCONV_FOZ_NUM_TAGS) {
Ok(newdb) => Mutex::new(Some(newdb)), Ok(newdb) => Mutex::new(Some(newdb)),
Err(_) => Mutex::new(None), Err(_) => Mutex::new(None),
} }
@ -237,7 +237,7 @@ impl VideoConvState {
gst_loggable_error!(CAT, "MEDIACONV_VIDEO_TRANSCODED_FILE is not set!") gst_loggable_error!(CAT, "MEDIACONV_VIDEO_TRANSCODED_FILE is not set!")
})?; })?;
let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), VIDEOCONV_FOZ_NUM_TAGS) { let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), true /* read-only? */, VIDEOCONV_FOZ_NUM_TAGS) {
Ok(s) => Some(s), Ok(s) => Some(s),
Err(_) => None, Err(_) => None,
}; };