Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient string concatenation #1105

Merged
merged 1 commit into from
Apr 28, 2020
Merged

Conversation

catenacyber
Copy link
Contributor

Found by oss-fuzz
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21892

The optimization comes from
https://hermanschaaf.com/efficient-string-concatenation-in-go/

My benchmark on the oss-fuzz test case is from 80 seconds to 0.1 second with this PR

Reproducer program is

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"runtime/pprof"

	"github.com/miekg/dns"
)

func main() {
	f, err := os.Create("cpu.prof")
	if err != nil {
		fmt.Printf("error %#+v\n", err)
		return
	}
	_ = pprof.StartCPUProfile(f)

	data, err := ioutil.ReadFile(os.Args[1])
	if err != nil {
		fmt.Printf("Failed to read corpus file", err)
	}
	fmt.Printf("Starting %s\n", os.Args[1])
	dns.NewRR(string(data))

	fmt.Printf("Finished\n")
	pprof.StopCPUProfile()
	f, err = os.Create("heap.prof")
	if err != nil {
		fmt.Printf("error %#+v\n", err)
		return
	}
	if err = pprof.WriteHeapProfile(f); err != nil {
		fmt.Printf("error %#+v\n", err)
		return
	}
	f.Close()
	fmt.Printf("end\n")
}

@codecov-io
Copy link

codecov-io commented Apr 27, 2020

Codecov Report

Merging #1105 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1105      +/-   ##
==========================================
+ Coverage   55.61%   55.66%   +0.04%     
==========================================
  Files          41       41              
  Lines       10082    10082              
==========================================
+ Hits         5607     5612       +5     
+ Misses       3445     3441       -4     
+ Partials     1030     1029       -1     
Impacted Files Coverage Δ
scan_rr.go 60.82% <100.00%> (ø)
server.go 70.71% <0.00%> (+0.27%) ⬆️
msg.go 77.36% <0.00%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6737387...ab3a6d6. Read the comment docs.

@miekg miekg merged commit 5bfe94b into miekg:master Apr 28, 2020
aanm pushed a commit to cilium/dns that referenced this pull request Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants