bytes -> bits typo

This commit is contained in:
Mateusz Poliwczak
2023-08-25 10:30:30 +02:00
parent 91a2552fd3
commit eb23195734
4 changed files with 6 additions and 6 deletions

View File

@@ -2000,7 +2000,7 @@ func (n *Name) pack(msg []byte, compression map[string]int, compressionOff int)
}
// Miss. Add the suffix to the compression table if the
// offset can be stored in the available 14 bytes.
// offset can be stored in the available 14 bits.
newPtr := len(msg) - compressionOff
if newPtr <= int(^uint16(0)>>2) {
if nameAsStr == "" {
@@ -2008,7 +2008,7 @@ func (n *Name) pack(msg []byte, compression map[string]int, compressionOff int)
// multiple times (for next labels).
nameAsStr = string(n.Data[:n.Length])
}
compression[string(n.Data[i:])] = newPtr
compression[nameAsStr[i:]] = newPtr
}
}
}

View File

@@ -1820,20 +1820,24 @@ func TestBuilderNameCompressionWithNonZeroedName(t *testing.T) {
if err := b.StartQuestions(); err != nil {
t.Fatalf("b.StartQuestions() unexpected error: %v", err)
}
name := MustNewName("go.dev.")
if err := b.Question(Question{Name: name}); err != nil {
t.Fatalf("b.Question() unexpected error: %v", err)
}
// Character that is not part of the name (name.Data[:name.Length]),
// shouldn't affect the compression algorithm.
name.Data[name.Length] = '1'
if err := b.Question(Question{Name: name}); err != nil {
t.Fatalf("b.Question() unexpected error: %v", err)
}
msg, err := b.Finish()
if err != nil {
t.Fatalf("b.Finish() unexpected error: %v", err)
}
expect := []byte{
0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, // header
2, 'g', 'o', 3, 'd', 'e', 'v', 0, 0, 0, 0, 0, // question 1

View File

@@ -1,2 +0,0 @@
go test fuzz v1
[]byte("0000\x00\x01\x00\x00\x00\x01\x00\x00\x000000\x01.\x0000000000\x00\x040000")

View File

@@ -1,2 +0,0 @@
go test fuzz v1
[]byte("0000\x00\x01\x00\x00\x00\x00\x00\x00\x01.\x000000")