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

fix: forbid index slicing in parser #92

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![build](https://img.shields.io/github/actions/workflow/status/hoodie/icalendar-rs/ci.yml?branch=main)](https://github.com/hoodie/icalendar-rs/actions?query=workflow%3A"Continuous+Integration")
[![Crates.io](https://img.shields.io/crates/d/icalendar)](https://crates.io/crates/icalendar)
[![contributors](https://img.shields.io/github/contributors/hoodie/icalendar-rs)](https://github.com/hoodie/icalendar-rs/graphs/contributors)
![maintenance](https://img.shields.io/maintenance/yes/2023)
![maintenance](https://img.shields.io/maintenance/yes/2025)

[![version](https://img.shields.io/crates/v/icalendar)](https://crates.io/crates/icalendar/)
[![documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.rs/icalendar/)
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
unused_import_braces,
unused_qualifications,
missing_debug_implementations,
clippy::indexing_slicing,
clippy::dbg_macro,
clippy::doc_markdown,
clippy::redundant_closure_for_method_calls
Expand Down
5 changes: 5 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ pub fn read_calendar(input: &str) -> Result<Calendar<'_>, String> {
.map_err(|e: VerboseError<&str>| format!("error: {}", convert_error(input, e.clone())))
}

#[test]
fn begin_crash() {
assert!(read_calendar("BEGIN:").is_ok());
}

/// Parse iCalendar file content into an array of [`Component`]s
///
/// This version produces nice and readable errors with line numbers thanks the the awesomeness of [`nom`].
Expand Down
2 changes: 1 addition & 1 deletion src/parser/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::parsed_string::ParseString;
pub fn property_key<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, &str, E> {
if &input[0..=2] == "END" || &input[0..=4] == "BEGIN" {
if input.get(0..=2) == Some("END") || input.get(0..=4) == Some("BEGIN") {
IResult::Err(Err::Error(nom::error::make_error(
input,
nom::error::ErrorKind::Satisfy,
Expand Down
1 change: 1 addition & 0 deletions src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl From<chrono::Duration> for Property {
//}

// Fold a content line as described in RFC 5545, Section 3.1
#[allow(clippy::indexing_slicing)]
pub(crate) fn fold_line(line: &str) -> String {
let limit = 75;
let len = line.len();
Expand Down