Skip to content

Commit 118a189

Browse files
committed
Bump MSRV to 1.80
1 parent 5d8654d commit 118a189

File tree

5 files changed

+17
-35
lines changed

5 files changed

+17
-35
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
rust: ["1.67.1", nightly, beta, stable]
17+
rust: ["1.80.1", nightly, beta, stable]
1818
steps:
1919
- uses: actions/checkout@v4
2020

2121
- uses: dtolnay/rust-toolchain@nightly
22-
if: ${{ matrix.rust == '1.67.1' }}
22+
if: ${{ matrix.rust == '1.80.1' }}
2323
- name: Generate Cargo.lock with minimal-version dependencies
24-
if: ${{ matrix.rust == '1.67.1' }}
24+
if: ${{ matrix.rust == '1.80.1' }}
2525
run: cargo -Zminimal-versions generate-lockfile
2626

2727
- uses: dtolnay/rust-toolchain@v1
@@ -34,7 +34,7 @@ jobs:
3434
- name: build
3535
run: cargo build -v
3636
- name: test
37-
if: ${{ matrix.rust != '1.67.1' }}
37+
if: ${{ matrix.rust != '1.80.1' }}
3838
run: cargo test -v && cargo doc -v
3939
- name: bench
4040
if: ${{ matrix.rust == 'nightly' }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "image-webp"
33
version = "0.2.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
6-
rust-version = "1.67.1"
6+
rust-version = "1.80.1"
77

88
description = "WebP encoding and decoding in pure Rust"
99
homepage = "https://github.com/image-rs/image-webp"

src/decoder.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use byteorder_lite::{LittleEndian, ReadBytesExt};
22
use quick_error::quick_error;
33

44
use std::collections::HashMap;
5-
use std::io::{self, BufRead, BufReader, Cursor, Read, Seek};
5+
use std::io::{self, BufRead, Cursor, Read, Seek};
66
use std::num::NonZeroU16;
77
use std::ops::Range;
88

@@ -385,15 +385,8 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
385385
let max_position = position + riff_size.saturating_sub(12);
386386
self.r.seek(io::SeekFrom::Start(position))?;
387387

388-
// Resist denial of service attacks by using a BufReader. In most images there
389-
// should be a very small number of chunks. However, nothing prevents a malicious
390-
// image from having an extremely large number of "unknown" chunks. Issuing
391-
// millions of reads and seeks against the underlying reader might be very
392-
// expensive.
393-
let mut reader = BufReader::with_capacity(64 << 10, &mut self.r);
394-
395388
while position < max_position {
396-
match read_chunk_header(&mut reader) {
389+
match read_chunk_header(&mut self.r) {
397390
Ok((chunk, chunk_size, chunk_size_rounded)) => {
398391
let range = position + 8..position + 8 + chunk_size;
399392
position += 8 + chunk_size_rounded;
@@ -408,8 +401,8 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
408401
return Err(DecodingError::InvalidChunkSize);
409402
}
410403

411-
reader.seek_relative(12)?;
412-
let duration = reader.read_u32::<LittleEndian>()? & 0xffffff;
404+
self.r.seek_relative(12)?;
405+
let duration = self.r.read_u32::<LittleEndian>()? & 0xffffff;
413406
self.loop_duration =
414407
self.loop_duration.wrapping_add(u64::from(duration));
415408

@@ -419,19 +412,19 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
419412
// and the spec says that lossless images SHOULD NOT contain ALPH
420413
// chunks, so we treat both as indicators of lossy images.
421414
if !self.is_lossy {
422-
let (subchunk, ..) = read_chunk_header(&mut reader)?;
415+
let (subchunk, ..) = read_chunk_header(&mut self.r)?;
423416
if let WebPRiffChunk::VP8 | WebPRiffChunk::ALPH = subchunk {
424417
self.is_lossy = true;
425418
}
426-
reader.seek_relative(chunk_size_rounded as i64 - 24)?;
419+
self.r.seek_relative(chunk_size_rounded as i64 - 24)?;
427420
} else {
428-
reader.seek_relative(chunk_size_rounded as i64 - 16)?;
421+
self.r.seek_relative(chunk_size_rounded as i64 - 16)?;
429422
}
430423

431424
continue;
432425
}
433426

434-
reader.seek_relative(chunk_size_rounded as i64)?;
427+
self.r.seek_relative(chunk_size_rounded as i64)?;
435428
}
436429
Err(DecodingError::IoError(e))
437430
if e.kind() == io::ErrorKind::UnexpectedEof =>
@@ -884,13 +877,13 @@ pub(crate) fn range_reader<R: BufRead + Seek>(
884877
Ok(r.take(range.end - range.start))
885878
}
886879

887-
pub(crate) fn read_fourcc<R: Read>(mut r: R) -> Result<WebPRiffChunk, DecodingError> {
880+
pub(crate) fn read_fourcc<R: BufRead>(mut r: R) -> Result<WebPRiffChunk, DecodingError> {
888881
let mut chunk_fourcc = [0; 4];
889882
r.read_exact(&mut chunk_fourcc)?;
890883
Ok(WebPRiffChunk::from_fourcc(chunk_fourcc))
891884
}
892885

893-
pub(crate) fn read_chunk_header<R: Read>(
886+
pub(crate) fn read_chunk_header<R: BufRead>(
894887
mut r: R,
895888
) -> Result<(WebPRiffChunk, u64, u64), DecodingError> {
896889
let chunk = read_fourcc(&mut r)?;

src/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn write_huffman_tree<W: Write>(
286286

287287
fn length_to_symbol(len: u16) -> (u16, u8) {
288288
let len = len - 1;
289-
let highest_bit = 15 - len.leading_zeros() as u16; // TODO: use ilog2 once MSRV >= 1.67
289+
let highest_bit = len.ilog2() as u16;
290290
let second_highest_bit = (len >> (highest_bit - 1)) & 1;
291291
let extra_bits = highest_bit - 1;
292292
let symbol = 2 * highest_bit + second_highest_bit;

src/lossless_transform.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,6 @@ pub(crate) fn apply_color_indexing_transform(
381381
table_size: u16,
382382
table_data: &[u8],
383383
) {
384-
// TODO: Replace with built-in div_ceil when MSRV is 1.73+
385-
fn div_ceil(a: u16, b: u16) -> u16 {
386-
let d = a / b;
387-
let r = a % b;
388-
if r > 0 && b > 0 {
389-
d + 1
390-
} else {
391-
d
392-
}
393-
}
394-
395384
if table_size > 16 {
396385
let mut table = table_data.chunks_exact(4).collect::<Vec<_>>();
397386
table.resize(256, &[0; 4]);
@@ -429,7 +418,7 @@ pub(crate) fn apply_color_indexing_transform(
429418
let table = table.chunks_exact(4 << width_bits).collect::<Vec<_>>();
430419

431420
let entry_size = 4 << width_bits;
432-
let index_image_width = div_ceil(width, 1 << width_bits) as usize;
421+
let index_image_width = width.div_ceil(1 << width_bits) as usize;
433422
let final_entry_size = width as usize * 4 - entry_size * (index_image_width - 1);
434423

435424
for y in (0..height as usize).rev() {

0 commit comments

Comments
 (0)