Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10ad90ba22 | ||
|
|
45eac1f6f8 | ||
|
|
b91e92b070 |
+7
-2
@@ -14,7 +14,9 @@ RUN touch mfer/mf.pb.go
|
|||||||
# Go half of fmt-check only: this image has no node, so no prettier. The
|
# Go half of fmt-check only: this image has no node, so no prettier. The
|
||||||
# markdown half runs in the mdfmt stage below.
|
# markdown half runs in the mdfmt stage below.
|
||||||
RUN make fmt-check-go
|
RUN make fmt-check-go
|
||||||
RUN make lint
|
# The linter directly, not `make lint`: script/lint builds this stage, and
|
||||||
|
# there is no docker inside this build.
|
||||||
|
RUN golangci-lint run --config .golangci.yml ./...
|
||||||
|
|
||||||
# Markdown/JSON format stage — prettier needs node, which the Go images
|
# Markdown/JSON format stage — prettier needs node, which the Go images
|
||||||
# do not have. node:22.17.0-bookworm-slim (2026-08-09); ships node
|
# do not have. node:22.17.0-bookworm-slim (2026-08-09); ships node
|
||||||
@@ -67,7 +69,10 @@ RUN version="${VERSION:-$(git describe --tags --always)}"; \
|
|||||||
exit 1; \
|
exit 1; \
|
||||||
fi; \
|
fi; \
|
||||||
cd cmd/mfer && \
|
cd cmd/mfer && \
|
||||||
go build -tags urfave_cli_no_docs -ldflags "-X main.Gitrev=$version" -o /mfer .
|
CGO_ENABLED=0 go build -tags urfave_cli_no_docs -ldflags "-X main.Gitrev=$version" -o /mfer .
|
||||||
|
|
||||||
|
# Fail unless /mfer is statically linked: scratch has no C library to run it.
|
||||||
|
RUN ldd /mfer 2>&1 | grep -q 'not a dynamic executable'
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=builder /mfer /mfer
|
COPY --from=builder /mfer /mfer
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ The `innerMessage` field is compressed with
|
|||||||
enforce a decompression size limit to prevent decompression bombs. The reference
|
enforce a decompression size limit to prevent decompression bombs. The reference
|
||||||
implementation limits decompressed size to 256 MB. It writes zstd frames with a
|
implementation limits decompressed size to 256 MB. It writes zstd frames with a
|
||||||
window of at most 8 MiB, the largest window the zstd format recommends decoders
|
window of at most 8 MiB, the largest window the zstd format recommends decoders
|
||||||
support, and refuses frames that ask for a larger one.
|
support, and refuses frames that ask for a larger one. It also refuses an inner
|
||||||
|
message whose file entries, hashes, timestamps and MIME types, counted at 160,
|
||||||
|
112, 64 and 16 bytes each, add up to more than 8 times its size.
|
||||||
|
|
||||||
## Inner Message (`MFFile`)
|
## Inner Message (`MFFile`)
|
||||||
|
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ fmt-check-md:
|
|||||||
hooks:
|
hooks:
|
||||||
@script/install-precommit
|
@script/install-precommit
|
||||||
|
|
||||||
devprereqs:
|
|
||||||
which golangci-lint || go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2
|
|
||||||
|
|
||||||
mfer/mf.pb.go: mfer/mf.proto
|
mfer/mf.pb.go: mfer/mf.proto
|
||||||
cd mfer && go generate .
|
cd mfer && go generate .
|
||||||
|
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ standard: normalized scripts in `script/` are the entrypoints for the
|
|||||||
development workflow, and the Makefile targets are thin shims that call them. We
|
development workflow, and the Makefile targets are thin shims that call them. We
|
||||||
provide:
|
provide:
|
||||||
|
|
||||||
- `script/bootstrap` — install all dependencies (Go, golangci-lint, Go module
|
- `script/bootstrap` — install all dependencies (Go, Go module download, and
|
||||||
download, and node/yarn plus the prettier version pinned in
|
node/yarn plus the prettier version pinned in `package.json`/`yarn.lock`),
|
||||||
`package.json`/`yarn.lock`), idempotently
|
idempotently; golangci-lint is not installed, it runs only in Docker
|
||||||
- `script/setup` — make a fresh clone ready for development: runs
|
- `script/setup` — make a fresh clone ready for development: runs
|
||||||
`script/bootstrap`, then `script/install-precommit`
|
`script/bootstrap`, then `script/install-precommit`
|
||||||
- `script/projectname` — output the project name (`mfer`); used by other scripts
|
- `script/projectname` — output the project name (`mfer`); used by other scripts
|
||||||
@@ -77,9 +77,11 @@ provide:
|
|||||||
- `script/fuzz` — fuzz the manifest parser for one minute; run by hand
|
- `script/fuzz` — fuzz the manifest parser for one minute; run by hand
|
||||||
(`make fuzz`), never by CI, while `script/test` runs its committed seed corpus
|
(`make fuzz`), never by CI, while `script/test` runs its committed seed corpus
|
||||||
as ordinary tests
|
as ordinary tests
|
||||||
- `script/lint` — run `golangci-lint` and verify `gofmt` cleanliness
|
- `script/lint` — run `golangci-lint` in Docker: builds only the `lint` stage of
|
||||||
- `script/fmt` — format all code and docs (writes): `gofumpt`,
|
the `Dockerfile` (the Go format check, then the linter), uncached so it runs
|
||||||
`golangci-lint run --fix`, and `script/prettier --write`
|
every time, then removes the image
|
||||||
|
- `script/fmt` — format all code and docs (writes): `gofumpt` and
|
||||||
|
`script/prettier --write`
|
||||||
- `script/prettier` — run prettier over the repository's canonical file set
|
- `script/prettier` — run prettier over the repository's canonical file set
|
||||||
(Markdown and JSON, minus `.prettierignore`) in the given mode, `--write` or
|
(Markdown and JSON, minus `.prettierignore`) in the given mode, `--write` or
|
||||||
`--check`; the single definition of that file set, so `script/fmt` and
|
`--check`; the single definition of that file set, so `script/fmt` and
|
||||||
@@ -105,11 +107,10 @@ yet. Primary development happens on a privately-run Gitea instance at
|
|||||||
[tracked there](https://git.eeqj.de/sneak/mfer/issues).
|
[tracked there](https://git.eeqj.de/sneak/mfer/issues).
|
||||||
|
|
||||||
Changes must always be formatted with a standard `go fmt`, syntactically valid,
|
Changes must always be formatted with a standard `go fmt`, syntactically valid,
|
||||||
and must pass the linting defined in the repository (presently only the
|
and must pass the linting defined in the repository's `.golangci.yml`, which
|
||||||
`golangci-lint` defaults), which can be run with a `make lint`. The `main`
|
`make lint` runs in Docker. The `main` branch is protected and all changes must
|
||||||
branch is protected and all changes must be made via
|
be made via [pull requests](https://git.eeqj.de/sneak/mfer/pulls) and pass CI to
|
||||||
[pull requests](https://git.eeqj.de/sneak/mfer/pulls) and pass CI to be merged.
|
be merged. Any changes submitted to this project must also be
|
||||||
Any changes submitted to this project must also be
|
|
||||||
[WTFPL-licensed](https://wtfpl.net) to be considered.
|
[WTFPL-licensed](https://wtfpl.net) to be considered.
|
||||||
|
|
||||||
See [`REPO_POLICIES.md`](REPO_POLICIES.md) for detailed coding standards,
|
See [`REPO_POLICIES.md`](REPO_POLICIES.md) for detailed coding standards,
|
||||||
|
|||||||
+4
-1
@@ -35,6 +35,9 @@ const (
|
|||||||
decodedTimestampSize = 64
|
decodedTimestampSize = 64
|
||||||
decodedMIMETypeSize = 16
|
decodedMIMETypeSize = 16
|
||||||
|
|
||||||
// The densest manifests mfer writes add up to about 7 times their size.
|
// Each file entry mfer writes holds a path of at least one byte, a
|
||||||
|
// 34-byte SHA-256 multihash and a modification time: at least 47 bytes,
|
||||||
|
// counted at 336. So its manifests add up to at most about 7.15 times
|
||||||
|
// their size, and this limit is about 12% above that.
|
||||||
maxDecodedGrowth = 8
|
maxDecodedGrowth = 8
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -76,9 +76,8 @@ func FuzzNewManifestFromReader(f *testing.F) {
|
|||||||
// fails if the decoder accepts windows of twice zstdWindowSize; the
|
// fails if the decoder accepts windows of twice zstdWindowSize; the
|
||||||
// seed whose two frames together exceed MaxDecompressedSize fails
|
// seed whose two frames together exceed MaxDecompressedSize fails
|
||||||
// if the decoder decodes them in full instead of stopping at the
|
// if the decoder decodes them in full instead of stopping at the
|
||||||
// declared size; the seeds of empty file entries, of a file entry
|
// declared size; the seeds of empty file entries and of a file
|
||||||
// of empty hashes, and of file entries of only an empty MIME type
|
// entry of empty hashes fail if the parser decodes them.
|
||||||
// and empty times fail if the parser decodes them.
|
|
||||||
limit := 20*(uint64(len(data))+decompressed) + 24*zstdWindowSize
|
limit := 20*(uint64(len(data))+decompressed) + 24*zstdWindowSize
|
||||||
|
|
||||||
allocated := after.TotalAlloc - before.TotalAlloc
|
allocated := after.TotalAlloc - before.TotalAlloc
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -116,29 +117,55 @@ func TestDeserializeRejectsInvalidEntryPaths(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entries of a one-character path and empty modification and change times
|
// Entries of a path, an empty hash, an empty MIME type and empty modification
|
||||||
// pass every other check, but would take about 23 times their size to decode.
|
// and change times are counted at 416 bytes each (160 + 112 + 16 + 64 + 64)
|
||||||
|
// and take 16 bytes plus the path to encode. A 35-character path makes that
|
||||||
|
// 51 bytes, about 8.2 times: refused, and leaving any one of the five
|
||||||
|
// uncounted, even the MIME type, brings it under 8. A 37-character path makes
|
||||||
|
// it 53 bytes, about 7.8 times: loaded.
|
||||||
func TestDeserializeRefusesEntriesThatDecodeTooLarge(t *testing.T) {
|
func TestDeserializeRefusesEntriesThatDecodeTooLarge(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
entry := protowire.AppendTag(nil, 1, protowire.BytesType) // MFFilePath.path
|
tests := []struct {
|
||||||
entry = protowire.AppendString(entry, "a")
|
pathLen int
|
||||||
entry = protowire.AppendTag(entry, 302, protowire.BytesType) // MFFilePath.mtime
|
refused bool
|
||||||
entry = protowire.AppendBytes(entry, nil)
|
}{
|
||||||
entry = protowire.AppendTag(entry, 303, protowire.BytesType) // MFFilePath.ctime
|
{35, true},
|
||||||
entry = protowire.AppendBytes(entry, nil)
|
{37, false},
|
||||||
|
|
||||||
id := uuid.New()
|
|
||||||
inner := protowire.AppendTag(nil, 102, protowire.BytesType) // MFFile.uuid
|
|
||||||
inner = protowire.AppendBytes(inner, id[:])
|
|
||||||
|
|
||||||
for range 1000 {
|
|
||||||
inner = protowire.AppendTag(inner, 101, protowire.BytesType) // MFFile.files
|
|
||||||
inner = protowire.AppendBytes(inner, entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := NewManifestFromReader(bytes.NewReader(wrapInner(t, id, inner)))
|
for _, tt := range tests {
|
||||||
require.ErrorIs(t, err, errDecodedTooLarge)
|
t.Run(strconv.Itoa(tt.pathLen), func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
entry := protowire.AppendTag(nil, 1, protowire.BytesType) // MFFilePath.path
|
||||||
|
entry = protowire.AppendString(entry, strings.Repeat("a", tt.pathLen))
|
||||||
|
entry = protowire.AppendTag(entry, 3, protowire.BytesType) // MFFilePath.hashes
|
||||||
|
entry = protowire.AppendBytes(entry, nil)
|
||||||
|
entry = protowire.AppendTag(entry, 301, protowire.BytesType) // MFFilePath.mimeType
|
||||||
|
entry = protowire.AppendBytes(entry, nil)
|
||||||
|
entry = protowire.AppendTag(entry, 302, protowire.BytesType) // MFFilePath.mtime
|
||||||
|
entry = protowire.AppendBytes(entry, nil)
|
||||||
|
entry = protowire.AppendTag(entry, 303, protowire.BytesType) // MFFilePath.ctime
|
||||||
|
entry = protowire.AppendBytes(entry, nil)
|
||||||
|
|
||||||
|
id := uuid.New()
|
||||||
|
inner := protowire.AppendTag(nil, 102, protowire.BytesType) // MFFile.uuid
|
||||||
|
inner = protowire.AppendBytes(inner, id[:])
|
||||||
|
|
||||||
|
for range 1000 {
|
||||||
|
inner = protowire.AppendTag(inner, 101, protowire.BytesType) // MFFile.files
|
||||||
|
inner = protowire.AppendBytes(inner, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := NewManifestFromReader(bytes.NewReader(wrapInner(t, id, inner)))
|
||||||
|
if tt.refused {
|
||||||
|
require.ErrorIs(t, err, errDecodedTooLarge)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Many empty files with names of at most three characters and modification
|
// Many empty files with names of at most three characters and modification
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-6
@@ -140,12 +140,7 @@ main() {
|
|||||||
|
|
||||||
# ---- Go repos ----
|
# ---- Go repos ----
|
||||||
if missing go; then pkg_install go golang go go; fi
|
if missing go; then pkg_install go golang go go; fi
|
||||||
# golangci-lint: packaged in nix, brew, and apk. On apt there is no
|
# No golangci-lint: script/lint runs it in Docker only.
|
||||||
# package: download a specific release archive from GitHub and
|
|
||||||
# verify its hash (verify_sha256), never curl | sh.
|
|
||||||
if missing golangci-lint; then
|
|
||||||
pkg_install golangci-lint golangci-lint golangci-lint golangci-lint
|
|
||||||
fi
|
|
||||||
go mod download
|
go mod download
|
||||||
|
|
||||||
# ---- Python repos ----
|
# ---- Python repos ----
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ main() {
|
|||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
ensure_pb
|
ensure_pb
|
||||||
gofumpt -l -w mfer internal cmd
|
gofumpt -l -w mfer internal cmd
|
||||||
golangci-lint run --fix
|
|
||||||
# Markdown and JSON, over the same file set script/fmt-check verifies.
|
# Markdown and JSON, over the same file set script/fmt-check verifies.
|
||||||
"$SCRIPT_DIR/prettier" --write
|
"$SCRIPT_DIR/prettier" --write
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-8
@@ -1,17 +1,20 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# script/lint: run the linter.
|
# script/lint: run golangci-lint, in Docker only. Builds the lint stage of
|
||||||
|
# the Dockerfile, whose build runs the linter, so a successful build is a
|
||||||
|
# clean lint. --no-cache because a cached build runs no linter. The image
|
||||||
|
# is removed afterwards, whatever the outcome.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
|
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
golangci-lint run
|
# Tagged per run, so concurrent runs never remove each other's image.
|
||||||
if [ -n "$(gofmt -l .)" ]; then
|
image="$("$SCRIPT_DIR/projectname")-lint:$$"
|
||||||
echo "gofmt: files need formatting:" >&2
|
# A failed build leaves no image, so there is nothing to remove then.
|
||||||
gofmt -l . >&2
|
trap 'docker image rm "$image" >/dev/null 2>&1 || true' EXIT INT TERM
|
||||||
exit 1
|
docker build --no-cache --target lint -t "$image" .
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user