Skip to content

crane:registry serve doesn't handle corrupted blob #2124

@nianyush

Description

@nianyush

Describe the bug

A clear and concise description of what the bug is.

-rw------- 1 root root    0 Aug 11 01:52 0415b41f19c23728350392c5841531ad006fd52d40c9db0195c7488d73f15159
-rw------- 1 root root    0 Aug 11 01:52 3a151ec0926b069a01435974ebbedc2337413731bbd25ca8e6f0fa869136e0dc
-rw------- 1 root root    0 Aug 11 01:52 8a72cdd125e4cbe990498f68c8ff157c601ad34dc25748d4da06a76a7006db17
-rw------- 1 root root    0 Aug 11 01:52 3c2cafe5d7fd4de1ac92665e337245297d16ac93a8a9dd8b3ba2514e334925aa
-rw------- 1 root root    0 Aug 11 01:52 1779d2f3c54da806a597f59a50879a74c0836a16959bce7bb57792bbe0da4d17
-rw------- 1 root root    0 Aug 11 01:52 30c27442d56a6362a5611863175235cb6508469be1298497ab279d315d223ebe
-rw------- 1 root root    0 Aug 11 01:52 eac2913ea2de3970fc03fa3b7fea07aeeb8e89530abbb9ee1948252690449a48
-rw------- 1 root root    0 Aug 11 01:52 33412d7e015fba4c3162313c5c6838749474e252c46f81bd12640bde8214a592
-rw------- 1 root root    0 Aug 11 01:52 58b9e2823d7d4c4a754c349ab3dbc1143fb78312a7d1ab7a16bf2286f6b177a1
-rw------- 1 root root    0 Aug 11 01:52 cca3d5a8bc0da06a44d37da83b3c9c0046aa0d937cff5f1a15de7f64223bea6c
-rw------- 1 root root    0 Aug 11 01:52 322bb5c744f96a16264e825089052e37ba12eab04594150034221e84a29b7e05
-rw------- 1 root root    0 Aug 11 01:52 01d036902a3ca86e8793073c8094cba44d83a38953a489ac0641f3de017fe2d2
-rw------- 1 root root    0 Aug 11 01:52 e8f6b925bde1e43ab85b8d2203ce732af9d5df890529fd907eb0721a574094bd

We got a bunch of empty size blobs due to a restart of registry while pushing. After starting registry again on the same disk path, it would return this error on fetching that blob

GET http://xxxx/v2/bundle/xxxx:xxx/blobs/sha256:8a72cdd125e4cbe990498f68c8ff157c601ad34dc25748d4da06a76a7006db17: Content-Length header 0 does not match expected size 2149;

To Reproduce

  1. Start a registry with a specific disk path
  2. Upload some images to it and kill registry during upload
  3. start registry again
  4. make a fetch blob call

Expected behavior

A clear and concise description of what you expected to happen.

Disk blob handler should verify blob hash so it wont allow corrupted files.

IMO, we can do something like this

func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error) {

func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error) {
	fi, err := os.Stat(m.blobHashPath(h))
	if errors.Is(err, os.ErrNotExist) {
		return 0, errNotFound
	} else if err != nil {
		return 0, err
	}

// calculate hash of file at m.blobHashPath(h)
// compare this hash with h

	return fi.Size(), nil
}

Additional context

Add any other context about the problem here.

  • Output of crane version
  • Registry used (e.g., GCR, ECR, Quay)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions