Skip to content

Commit

Permalink
Fixed riff signature for files other than webp
Browse files Browse the repository at this point in the history
  • Loading branch information
VendoAU committed Dec 26, 2024
1 parent a7c0fe3 commit ccb1c45
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/structures/riff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@ pub struct RIFFHeader {

/// Parse a RIFF image header
pub fn parse_riff_header(riff_data: &[u8]) -> Result<RIFFHeader, StructureError> {
const MAGIC1: usize = 0x46464952;
const MAGIC2: usize = 0x50424557;
const MAGIC: usize = 0x46464952;

const CHUNK_TYPE_START: usize = 12;
const CHUNK_TYPE_END: usize = 15;
const CHUNK_TYPE_START: usize = 8;
const CHUNK_TYPE_END: usize = 12;

const FILE_SIZE_OFFSET: usize = 8;

let riff_structure = vec![
("magic1", "u32"),
("magic", "u32"),
("file_size", "u32"),
("magic2", "u32"),
("chunk_type", "u32"),
];

// Parse the riff header
if let Ok(riff_header) = common::parse(riff_data, &riff_structure, "little") {
// Sanity check expected magic bytes
if riff_header["magic1"] == MAGIC1 && riff_header["magic2"] == MAGIC2 {
// Get the RIFF type string (e.g., "WAV")
if riff_header["magic"] == MAGIC {
// Get the RIFF type string (e.g., "WAVE")
if let Ok(type_string) =
String::from_utf8(riff_data[CHUNK_TYPE_START..CHUNK_TYPE_END].to_vec())
{
Expand Down

0 comments on commit ccb1c45

Please sign in to comment.