suckit icon indicating copy to clipboard operation
suckit copied to clipboard

Use of Unsafe

Open pinkforest opened this issue 4 years ago • 0 comments

@Skallwar @CohenArthur

I ran a geiger and came across couple of unsafes.

Wonder if there were any specific intentions for these? (I didn't get into it too deep yet and found no previous issue tracking these)

src/dom.rs:                if let Some(url) = unsafe { (*attributes).get_mut(*attribute) } {
src/scraper.rs:        let data_utf8 = unsafe { String::from_utf8_unchecked(Vec::from(data)) };

src/dom.rs

        for node in nodes {
            let attributes = node.deref().attributes.as_ptr();
            for attribute in CSS_ATTRIBUTES.iter() {
                if let Some(url) = unsafe { (*attributes).get_mut(*attribute) } {
                    vec.push(url);
                }
            }
        }

src/scraper.rs

    fn find_charset(data: &[u8], http_charset: Option<String>) -> Option<String> {
        lazy_static! {
            static ref CHARSET_REGEX: Regex =
                Regex::new("<meta.*charset\\s*=\\s*\"?([^\"\\s;>]+).*>").unwrap();
        }

        // We don't know the real charset yet. We hope that the charset is ASCII
        // compatible, because Rust String are in UTF-8 (also ASCII compatible).
        let data_utf8 = unsafe { String::from_utf8_unchecked(Vec::from(data)) };
        let captures = CHARSET_REGEX.captures_iter(&data_utf8).next();

pinkforest avatar Jul 06 '21 17:07 pinkforest