Neopallium / jpeg2k

Safe wrapper for openjpeg-sys.
MIT License
6 stars 7 forks source link

error[E0308]: mismatched types: openjp2-0.3.0/src/j2k.rs:1717:27 #5

Closed luckfamousa closed 6 months ago

luckfamousa commented 7 months ago

When I try to build an app using jpeg2k using Docker on a M2 Mac I get a number of errors of this type:

45.46 error[E0308]: mismatched types
45.46     --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/openjp2-0.3.0/src/j2k.rs:1717:27
45.46      |
45.46 1717 |   l_comment_size = strlen(l_comment) as OPJ_UINT32;
45.46      |                    ------ ^^^^^^^^^ expected `*const u8`, found `*const i8`
45.46      |                    |
45.46      |                    arguments to this function are incorrect
45.46      |
45.46      = note: expected raw pointer `*const u8`
45.46                 found raw pointer `*const i8`
45.46 note: function defined here
45.46     --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/openjp2-0.3.0/src/j2k.rs:32:6
45.46      |
45.46 32   |   fn strlen(_: *const core::ffi::c_char) -> usize;
45.46      |      ^^^^^^

The Dockerfile I am using for building:

# Dockerfile
# Use an official Rust image as the base
FROM rust:bookworm as builder

# Create a new binary project
RUN USER=root cargo new --bin app
WORKDIR /app

# Copy the Rust project's files into the container
COPY ./ ./

# Build the Rust project
RUN cargo build --release
Neopallium commented 6 months ago

Did you change the default feature flags? By default it should be using the openjpeg-sys backend (C code) instead of openjp2 backend (Rust code). I don't have a Mac to test on, but I will try that docker file.

Neopallium commented 6 months ago

I was able to use that Dockerfile to build jpeg2k with both backends (openjpeg-sys and openjp2). I don't really recommend using the openjp2 backend yet, it is still mostly unsafe Rust code (converted from C code).

If you need sandboxing to process Jpeg2000 images, I would recommend using this wrapper: https://github.com/Neopallium/jpeg2k-sandboxed

It compiles the Jpeg2k code into a WebAssembly module and then runs it inside a wasmtime sandbox.

Neopallium commented 6 months ago

I have published an update to openjp2 that should fix that error (0.3.1).

You can update your local Cargo.lock to pull in the fix: cargo update -p openjp2

Let me know if it still fails to compile.