| 1 |
# Rust BMP decoder |
| 2 |
|
| 3 |
This directory contains helpers, simplifications, and wrappers for exposing a |
| 4 |
custom Rust BMP decoder to other Skia code: |
| 5 |
|
| 6 |
* to `SkBmpRustCodec` |
| 7 |
|
| 8 |
## Chromium build instructions |
| 9 |
|
| 10 |
To build and test the code from this directory from Chromium: |
| 11 |
|
| 12 |
1. `autoninja -C out/... gfx_unittests blink_platform_unittests chrome` |
| 13 |
1. `out/.../gfx_unittests --gtest_filter=*BMP*` |
| 14 |
1. `out/.../blink_platform_unittests --gtest_filter=*BMP*` |
| 15 |
|
| 16 |
## Skia build instructions |
| 17 |
|
| 18 |
### Bazel |
| 19 |
|
| 20 |
To build the code from this directory from Skia: |
| 21 |
|
| 22 |
``` |
| 23 |
$ cd skia-repo-root |
| 24 |
$ bazelisk build //src/codec:rust_bmp_decoder //experimental/rust_bmp/... |
| 25 |
``` |
| 26 |
|
| 27 |
To run unit tests: |
| 28 |
|
| 29 |
``` |
| 30 |
$ bazelisk test //experimental/rust_bmp/ffi:test_bmp_ffi |
| 31 |
``` |
| 32 |
|
| 33 |
To build the fuzzer: |
| 34 |
|
| 35 |
``` |
| 36 |
$ bazelisk build //experimental/rust_bmp/ffi:fuzz_rust_bmp |
| 37 |
``` |
| 38 |
|
| 39 |
To run the fuzzer with the corpus: |
| 40 |
|
| 41 |
``` |
| 42 |
$ for bmp in experimental/rust_bmp/fuzz/corpus/*.bmp; do |
| 43 |
cat "$bmp" | bazel-bin/experimental/rust_bmp/ffi/fuzz_rust_bmp |
| 44 |
done |
| 45 |
``` |
| 46 |
|
| 47 |
See `validation_artifacts/TESTING.md` for detailed test documentation and `validation_artifacts/FUZZING.md` for fuzzing documentation. |
| 48 |
|
| 49 |
### gn / ninja |
| 50 |
|
| 51 |
To build the code from this directory from Skia: |
| 52 |
|
| 53 |
1. `gn args out/RustBmp` and set `skia_use_rust_bmp_decode = true` |
| 54 |
1. `gn gen out/RustBmp` |
| 55 |
1. `autoninja -C out/RustBmp dm` |
| 56 |
``` |
| 57 |
|
| 58 |
To test the code: |
| 59 |
|
| 60 |
``` |
| 61 |
$ out/RustBmp/dm --src tests --nogpu \ |
| 62 |
--match Codec_bmp |
| 63 |
``` |
| 64 |
|
| 65 |
## Features |
| 66 |
|
| 67 |
### **Complete Format Support** |
| 68 |
|
| 69 |
- **Bit Depths**: 1-bit, 4-bit, 8-bit, 16-bit, 24-bit, 32-bit |
| 70 |
- **Compression**: Uncompressed (BI_RGB), RLE4, RLE8, Bitfields (BI_BITFIELDS) |
| 71 |
- **Advanced**: OS/2 bitmap variants |
| 72 |
- **Color Spaces**: sRGB, embedded ICC profiles (when available) |
| 73 |
|
| 74 |
### **Security & Robustness** |
| 75 |
|
| 76 |
- **Memory Safety**: Complete overflow protection with u64 arithmetic |
| 77 |
- **Input Validation**: Comprehensive header and stream validation |
| 78 |
- **Corruption Detection**: Advanced detection of malformed files |
| 79 |
- **Standards Compliance**: 100% conformance with bmptestsuite-0.9 |
| 80 |
|
| 81 |
### **Performance & Integration** |
| 82 |
|
| 83 |
- **Zero-Copy**: Efficient memory handling with minimal allocations |
| 84 |
- **FFI Optimized**: Clean Rust-to-C++ interface via CXX bridge |
| 85 |
- **Conditional Build**: Integrated with Skia's build system |
| 86 |
|
| 87 |
## Architecture |
| 88 |
|
| 89 |
``` |
| 90 |
experimental/rust_bmp/ |
| 91 |
├── ffi/ # Rust implementation core |
| 92 |
│ ├── lib.rs # Crate root |
| 93 |
│ ├── FFI.rs # C++ interface bridge |
| 94 |
│ ├── bmp_decoder.rs # Main BMP decoding logic |
| 95 |
│ ├── bmp_header.rs # BMP header parsing and validation |
| 96 |
│ ├── bmp_constants.rs # Format constants and definitions |
| 97 |
│ ├── bmp_types.rs # Type definitions |
| 98 |
│ ├── bmp_icc.rs # ICC profile support through moxcms crate |
| 99 |
│ ├── bmp_jpeg_decoder.rs # Embedded JPEG handling through zune-jpeg crate |
| 100 |
│ ├── bmp_png_decoder.rs # Embedded PNG handling through png crate |
| 101 |
│ └── BUILD.bazel # Bazel build configuration |
| 102 |
├── decoder/ # C++ integration layer |
| 103 |
│ ├── SkBmpRustDecoder.h/.cpp # Skia SkCodec factory |
| 104 |
│ ├── impl/ |
| 105 |
│ │ └── SkBmpRustCodec.h/.cpp # Core codec implementation |
| 106 |
│ └── BUILD.bazel # Bazel build configuration |
| 107 |
└── README.md # This file |
| 108 |
``` |
| 109 |
|
| 110 |
## Differences between `SkBmpCodec` and `SkBmpRustCodec` |
| 111 |
|
| 112 |
* `SkBmpCodec`: |
| 113 |
- C++ implementation with manual memory management |
| 114 |
- Legacy codebase with accumulated technical debt |
| 115 |
* `SkBmpRustCodec` differences: |
| 116 |
- Memory-safe Rust implementation |
| 117 |
- Comprehensive overflow protection with u64 arithmetic |
| 118 |
- Enhanced corruption detection for malformed files |
| 119 |
- Improved BMP standards compliance |