Skip to content

fix(security): resolve font race, cap image and json sizes, and optimize threshold - #169

Merged
adcondev merged 3 commits into
masterfrom
fix/security-concurrency-and-perf
Oct 18, 2026
Merged

adcondev merged 3 commits into
masterfrom
fix/security-concurrency-and-perf

Conversation

@adcondev

Copy link
Copy Markdown
Owner

Summary (Area 1 / Phase 4)

  • Emulator Concurrency & Resource Safety (pkg/emulator): Protect FontManager.scaledFaces with sync.RWMutex, close discarded/cleared font.Face descriptors, and silence noisy library log.Printf calls.
  • Graphics DoS Guard, Profile MaxWidth & Threshold Speedup (pkg/graphics, pkg/document/executor): Enforce MaxImagePixelHeight = 32000, wire ImgOptions.MaxWidth from Profile.DotsPerLine (preventing 576px overflow on 58mm printers), and optimize applyThreshold with direct slice operations (~2.9x faster).
  • JSON DoS Guard & Profile-Aware QR Defaults (cmd/poster, pkg/service): Enforce constants.MaxJSONSize (10MB) via io.LimitReader, run doc.Validate() in --dry-run, and compute default QR MaxPixelWidth from Profile.DotsPerLine.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for opening this PR, @adcondev!

Here's what will happen next:

  • 🤖 Automated checks will run
  • 🏷️ Labels will be added automatically
  • 👀 A maintainer will review your changes

Please make sure:

  • ✅ All tests pass
  • 📝 The PR title follows conventional commits
  • 📋 The PR template is filled out completely

@adcondev
adcondev merged commit 9090ad1 into master Oct 18, 2026
13 checks passed
@adcondev
adcondev deleted the fix/security-concurrency-and-perf branch October 18, 2026 18:30
@github-actions

Copy link
Copy Markdown
Contributor

⚡ Benchmark Results

📈 Performance Comparison

📊 Click to expand detailed results

Current Branch Results

BenchmarkNewDocument-4    	1000000000	         0.3120 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3662116	       327.8 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  385500	      2915 ns/op	    1856 B/op	      29 allocs/op
BenchmarkToJSON-4         	  545520	      2072 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  500132	      2345 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	   85290	     12705 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  404768	      2839 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  272041	      4371 ns/op	     952 B/op	      22 allocs/op
BenchmarkTextCommandParsing-4       	  492547	      2247 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  234688	      4980 ns/op	    1000 B/op	      31 allocs/op
BenchmarkParseHexString-4           	 7979598	       149.9 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 6896658	       173.5 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	295574952	         4.067 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	31575561	        34.22 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	14509660	        81.62 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  501681	      2364 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  144378	      8262 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     597	   1961307 ns/op	 3469947 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     319	   3708005 ns/op	 5481093 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     138	   8719406 ns/op	 5231183 B/op	  230423 allocs/op

Base Branch Results

BenchmarkNewDocument-4    	1000000000	         0.3134 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3673240	       331.9 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  398298	      2980 ns/op	    1856 B/op	      29 allocs/op
BenchmarkToJSON-4         	  543748	      2075 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  480429	      2353 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	   92652	     12704 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  400984	      2899 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  266892	      4365 ns/op	     952 B/op	      22 allocs/op
BenchmarkTextCommandParsing-4       	  490024	      2225 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  230619	      4954 ns/op	    1000 B/op	      31 allocs/op
BenchmarkParseHexString-4           	 7394640	       161.2 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 6942878	       172.3 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	367007071	         3.272 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	33259261	        39.34 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	14732738	        83.35 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  504801	      2372 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  143481	      8274 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     598	   1958057 ns/op	 3469946 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     319	   3678092 ns/op	 5481087 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     136	   8635177 ns/op	 5231173 B/op	  230423 allocs/op

💡 Note: Use benchstat for statistical comparison

🎯 Summary

  • Total Benchmarks: 32
  • Average Speed: 2652890 ns/op
  • Average Memory: 2395405 B/op
  • Average Allocations: 41077 allocs/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant