• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cinode / go / 4801130633

25 Apr 2023 06:54PM UTC coverage: 90.273% (-0.2%) from 90.484%
4801130633

push

github

Bartłomiej Święcki
Fix validation of release docker images

1717 of 1902 relevant lines covered (90.27%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.36
/pkg/internal/blobtypes/dynamiclink/utils.go
1
/*
2
Copyright © 2022 Bartłomiej Święcki (byo)
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package dynamiclink
18

19
import (
20
        "encoding/binary"
21
        "errors"
22
        "fmt"
23
        "io"
24
)
25

26
func panicIf(b bool, msg interface{}) {
1✔
27
        if b {
2✔
28
                panic(fmt.Sprint(msg))
1✔
29
        }
30
}
31

32
func readBuff(r io.Reader, buff []byte, n string) error {
1✔
33
        _, err := io.ReadFull(r, buff)
1✔
34
        if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
2✔
35
                return fmt.Errorf("%w while reading %s", ErrInvalidDynamicLinkDataTruncated, n)
1✔
36
        }
1✔
37
        if err != nil {
2✔
38
                return err
1✔
39
        }
1✔
40
        return nil
1✔
41
}
42

43
func readDynamicSizeBuff(r io.Reader, n string) ([]byte, error) {
1✔
44
        size, err := readByte(r, n)
1✔
45
        if err != nil {
2✔
46
                return nil, err
1✔
47
        }
1✔
48
        if size >= 0x80 {
1✔
49
                return nil, fmt.Errorf("%w while reading %s", ErrInvalidDynamicLinkDataBlockSize, n)
×
50
        }
×
51
        ret := make([]byte, size)
1✔
52
        err = readBuff(r, ret, n)
1✔
53
        if err != nil {
2✔
54
                return nil, err
1✔
55
        }
1✔
56
        return ret, nil
1✔
57
}
58

59
func readByte(r io.Reader, n string) (byte, error) {
1✔
60
        var b [1]byte
1✔
61
        err := readBuff(r, b[:], n)
1✔
62
        return b[0], err
1✔
63
}
1✔
64

65
func readUint64(r io.Reader, n string) (uint64, error) {
1✔
66
        var b [8]byte
1✔
67
        err := readBuff(r, b[:], n)
1✔
68
        return binary.BigEndian.Uint64(b[:]), err
1✔
69
}
1✔
70

71
// note: below raises errors through panics,
72
// that's because it is assumed to write to byte buffers
73
// and hashers that should not return an error
74

75
func storeBuff(w io.Writer, b []byte) {
1✔
76
        c, err := w.Write(b)
1✔
77
        panicIf(err != nil, err)
1✔
78
        panicIf(c != len(b), io.ErrShortWrite)
1✔
79
}
1✔
80

81
func storeDynamicSizeBuff(w io.Writer, b []byte) {
1✔
82
        panicIf(len(b) >= 0x80, "Block size too large")
1✔
83

1✔
84
        storeByte(w, byte(len(b)))
1✔
85
        storeBuff(w, b)
1✔
86
}
1✔
87

88
func storeByte(w io.Writer, b byte) {
1✔
89
        storeBuff(w, []byte{b})
1✔
90
}
1✔
91

92
func storeUint64(w io.Writer, v uint64) {
1✔
93
        var b [8]byte
1✔
94
        binary.BigEndian.PutUint64(b[:], v)
1✔
95
        storeBuff(w, b[:])
1✔
96
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc