Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Unsafe #133

Open
pinkforest opened this issue Jul 6, 2021 · 0 comments
Open

Use of Unsafe #133

pinkforest opened this issue Jul 6, 2021 · 0 comments

Comments

@pinkforest
Copy link
Contributor

pinkforest commented Jul 6, 2021

@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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant