···11+MIT License
22+33+Copyright (c) 2025 Thomas Gazagnaire
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
+90
README.md
···11+# squashfs
22+33+SquashFS compressed filesystem reader in pure OCaml.
44+55+## Overview
66+77+SquashFS is a compressed read-only filesystem commonly used for:
88+- Linux initramfs/initrd images
99+- Container images (Docker, Snap packages)
1010+- Live CD/USB distributions
1111+- Embedded systems
1212+1313+This library provides read-only access to SquashFS 4.0 images.
1414+1515+## Features
1616+1717+- Read SquashFS superblock and metadata
1818+- Navigate directory structure
1919+- Read file contents
2020+- Read symbolic link targets
2121+- Supports gzip compression (zstd planned)
2222+- Pure OCaml, no external dependencies on squashfs-tools
2323+2424+## Installation
2525+2626+```
2727+opam install squashfs
2828+```
2929+3030+## Usage
3131+3232+```ocaml
3333+(* Open a SquashFS image *)
3434+let data = (* read image file *) in
3535+match Squashfs.of_string data with
3636+| Error msg -> Printf.eprintf "Error: %s\n" msg
3737+| Ok fs ->
3838+ (* Print superblock info *)
3939+ Format.printf "%a@." Squashfs.pp_superblock (Squashfs.superblock fs);
4040+4141+ (* List root directory *)
4242+ match Squashfs.readdir fs (Squashfs.root fs) with
4343+ | Error msg -> Printf.eprintf "Error: %s\n" msg
4444+ | Ok entries ->
4545+ List.iter (fun e ->
4646+ Format.printf "%s (%a)@." e.Squashfs.name
4747+ Squashfs.pp_file_type e.Squashfs.file_type
4848+ ) entries
4949+```
5050+5151+## API
5252+5353+### Opening Images
5454+5555+- `Squashfs.of_string` - Open from string data
5656+- `Squashfs.of_reader` - Open from bytesrw reader
5757+5858+### Navigation
5959+6060+- `Squashfs.root` - Get root directory inode
6161+- `Squashfs.readdir` - List directory entries
6262+- `Squashfs.lookup` - Look up entry by name
6363+- `Squashfs.resolve` - Resolve path to inode
6464+6565+### File Operations
6666+6767+- `Squashfs.read_file` - Read file contents
6868+- `Squashfs.read_link` - Read symlink target
6969+7070+### Inode Properties
7171+7272+- `Squashfs.inode_type` - File type
7373+- `Squashfs.inode_mode` - Permission bits
7474+- `Squashfs.inode_size` - File size
7575+- `Squashfs.inode_mtime` - Modification time
7676+7777+## Related Work
7878+7979+- [squashfs-tools](https://github.com/plougher/squashfs-tools) - Reference C implementation
8080+- [go-squashfs](https://github.com/CalebQ42/squashfs) - Go implementation
8181+- [rust-squashfs](https://github.com/wcampbell0x2a/backhand) - Rust implementation
8282+8383+## References
8484+8585+- [SquashFS Specification](https://dr-emann.github.io/squashfs/)
8686+- [Linux Kernel Documentation](https://www.kernel.org/doc/html/latest/filesystems/squashfs.html)
8787+8888+## License
8989+9090+MIT License. See [LICENSE.md](LICENSE.md) for details.
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Thomas Gazagnaire. All rights reserved.
33+ SPDX-License-Identifier: MIT
44+ ---------------------------------------------------------------------------*)
55+66+(** Fuzz tests for SquashFS.
77+88+ Key properties tested:
99+ 1. No crashes on malformed input
1010+ 2. Parser handles truncated data gracefully
1111+*)
1212+1313+open Crowbar
1414+1515+(* Property 1: No crashes on arbitrary input *)
1616+let test_no_crash input =
1717+ (* Should not raise exceptions, just return Error *)
1818+ match Squashfs.of_string input with
1919+ | Ok _ -> ()
2020+ | Error _ -> ()
2121+2222+(* Property 2: Valid magic prefix still handles corruption *)
2323+let test_corrupted_after_magic input =
2424+ (* Create data with valid magic but random rest *)
2525+ let magic = "hsqs" in
2626+ let data = magic ^ input in
2727+ match Squashfs.of_string data with
2828+ | Ok _ -> ()
2929+ | Error _ -> ()
3030+3131+let () =
3232+ add_test ~name:"squashfs: no crash on arbitrary input" [bytes] test_no_crash;
3333+ add_test ~name:"squashfs: handle corrupted data after magic" [bytes] test_corrupted_after_magic