Skip to content

[BUG] Panic in unsafe fill_rect_fast #461

Closed
@agersant

Description

@agersant

Describe the bug

When using Rust nightly compiler, attempting to draw a line is likely to cause a panic (depending on color / line coordinates):

thread 'main' panicked at 'misaligned pointer dereference: address must be a multiple of 0x8 but is 0x1ab590c7fd3', [redacted]\plotters-bitmap-0.3.2\src\bitmap_pixel\rgb.rs:215:29

The offending line is:

I believe the relevant Nightly change is rust-lang/rust#98112, but this seems to be a plotters bug and not a rustc regression (from my limited understanding).

To Reproduce

use plotters::prelude::*;

fn main() {
    let mut backend = BitMapBackend::new("test.png", (256, 256));
    backend.draw_line((1, 0), (100, 0), &RED).unwrap();
}

Sample project: https://github.com/agersant/plotter-panic

Version Information
Plotters 0.3.4

Activity

nbdd0121

nbdd0121 commented on Apr 5, 2023

@nbdd0121

That code does seem very broken:

  • The transmute call is wrong, because (u64, u64, u64) does not have any layout guarantees.
  • ptr comes from *mut [u8; 24], which doesn't have the correct alignment for u64.
pbdeuchler

pbdeuchler commented on Apr 11, 2023

@pbdeuchler
Contributor

I'm hitting this as well, but only when plotting a line series with a certain number of data points... i.e. purely adding more points to the same exact line "fixes" the issue.

noahdahlman

noahdahlman commented on Apr 17, 2023

@noahdahlman

I'm getting this as well, most of the examples I tried in the docs fail when using bitmap backend. I tried this example in a sample project and always got a panic, no issues when switching to SVG backend. Only fails on nightly (I'm using nightly-x86_64-unknown-linux-gnu ), stable works fine.

use plotters::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut backend = BitMapBackend::new("1.png", (300, 200));
    backend.draw_rect((50, 50), (200, 150), &RED, true)?;
    backend.present()?;
    Ok(())
}
Berrysoft

Berrysoft commented on Apr 20, 2023

@Berrysoft
Contributor

I also trigger this issue when trying to use plotters with slint with nightly toolchain. Anyway this code is broken, because you should use write_unaligned.

jayvdb

jayvdb commented on Jun 1, 2023

@jayvdb
Contributor

This now occurs on stable v1.70

Berrysoft

Berrysoft commented on Jun 3, 2023

@Berrysoft
Contributor

We need a new release.

ktjd123

ktjd123 commented on Jun 8, 2023

@ktjd123

I'm having error at blend_rect_fast 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jayvdb@pbdeuchler@agersant@nbdd0121@ktjd123

      Issue actions

        [BUG] Panic in unsafe `fill_rect_fast` · Issue #461 · plotters-rs/plotters