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

Release v2.0.0 #1

Merged
merged 3 commits into from
Sep 8, 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
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/1-problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Problem
about: Something does not seem right

---


7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/2-suggestion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Suggestion
about: Share how Serde could support your use case better

---


7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/3-documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Documentation
about: Certainly there is room for improvement

---


7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/4-other.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Anything else!
about: Whatever is on your mind

---


88 changes: 88 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:
schedule: [cron: "40 1 * * *"]

permissions:
contents: read

env:
RUSTFLAGS: -Dwarnings

jobs:
test:
name: Test suite
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo test
- uses: actions/upload-artifact@v4
if: always()
with:
name: Cargo.lock
path: Cargo.lock

stable:
name: Rust ${{matrix.rust}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable, beta]
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
- run: cargo build

nightly:
name: Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}}
runs-on: ${{matrix.os}}-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu]
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo build

doc:
name: Documentation
runs-on: ubuntu-latest
timeout-minutes: 45
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs

clippy:
name: Clippy
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@clippy
- run: cargo clippy -- -Dclippy::all -Dclippy::pedantic

# miri:
# name: Miri
# runs-on: ubuntu-latest
# timeout-minutes: 45
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@miri
# - run: cargo miri setup
# - run: cargo miri test
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

# 2.0.0 (8 Sept 2024)

- **added:** Github CI
- **fixed:** Clippy offences
- **changed:** Improve docs
- **changed:** Stablised return values to `u64`. Use of `usize` will need to be re-evaluated for future `no-std` support.

See [PR for changes](https://github.com/bsodmike/better-limit-reader-rs/pull/1/files)


# 1.0.2 (7 Sept 2024)

- **changed:** Add enhancement task to README
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "better-limit-reader"
version = "1.0.2"
version = "2.0.0"
authors = ["Michael de Silva <michael@cyberdynea.io>"]
description = "Configurable limit reader that limits the number of bytes read from an underlying reader, supporting decompression from Gzip and Zlib compressed via `flate2`"
readme = "README.md"
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# better-limit-reader-rs

![Crates.io Version](https://img.shields.io/crates/v/better-limit-reader)
[![Crates.io Version](https://img.shields.io/crates/v/better-limit-reader)](https://crates.io/crates/better-limit-reader)
[![Released API docs](https://img.shields.io/docsrs/better-limit-reader)](https://docs.rs/better-limit-reader/)

Exposes LimitReader which is a limit reader, that protects against zip-bombs and other nefarious activities that limits the number of bytes read from an underlying reader.

This crate is heavily inspired by Jon Gjengset’s “Crust of Rust” episode on the [inner workings of git on YouTube](https://youtu.be/u0VotuGzD_w?si=oIuV9CITSWHJXKBu&t=3503) and mitigrating Zip-bombs.

It has been said, the name is a bit _boisterous_, but at least it sets high ambitions for this wee crate.

## API usage

Refer to the [docs](https://docs.rs/better-limit-reader/latest/better_limit_reader/) for further examples.

### Upcoming enhancements
### Upcoming enhancements (in no particular order)

- [ ] Gzip decompression.
- [ ] `no_std` support (?); This needs planning via an issue on Github.
- TBD: If you have any requests, please open an issue!

### Building
Expand Down
2 changes: 1 addition & 1 deletion examples/read_limited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> LimitReaderResult<()> {
);

let data = limit_reader.buffer();
let text = String::from_utf8(data[..bytes_read].to_vec())?;
let text = String::from_utf8(data[..(bytes_read as usize)].to_vec())?;

println!("First line from README: {}", &text);

Expand Down
13 changes: 12 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ use crate::{error_from, LimitReaderOutputBuilderError};
use std::{
error::Error as StdError,
fmt::{self},
num::TryFromIntError,
string::FromUtf8Error,
};

/// Boxed error, a ptr to the Error via dynamic dispatch allocated on the heap at run time.
#[allow(clippy::module_name_repetitions)]
pub type BoxError = Box<dyn StdError + Send + Sync>;

/// Default error type for create.
#[allow(clippy::module_name_repetitions)]
pub type LimitReaderError = Error;

/// Error type
Expand All @@ -19,20 +22,27 @@ pub struct Error {

#[derive(Debug)]
#[non_exhaustive]
#[allow(clippy::module_name_repetitions)]
#[allow(clippy::enum_variant_names)]
pub enum ErrorKind {
IoError,
Utf8Error,
LimitReaderOutputBuilderError,
Utf8Error,
TryFromIntError,
LimitReaderError(Box<dyn StdError + Send + Sync>),
}

impl ErrorKind {
pub(crate) fn as_str(&self) -> &'static str {
#[allow(clippy::enum_glob_use)]
use ErrorKind::*;
// tidy-alphabetical-start
match *self {
IoError => "io error",
Utf8Error => "invalid utf-8",
LimitReaderOutputBuilderError => "builder error",
TryFromIntError => "conversion error",
LimitReaderError(_) => "boxed error",
}
}
}
Expand Down Expand Up @@ -78,6 +88,7 @@ error_from!(
LimitReaderOutputBuilderError,
ErrorKind::LimitReaderOutputBuilderError
);
error_from!(TryFromIntError, ErrorKind::TryFromIntError);

#[macro_use]
pub mod macros {
Expand Down
Loading