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

DAP Server fails when dealing with some binary data #756

Closed
marianosimone opened this issue Sep 21, 2022 · 0 comments · Fixed by #758
Closed

DAP Server fails when dealing with some binary data #756

marianosimone opened this issue Sep 21, 2022 · 0 comments · Fixed by #758
Labels
bug Something isn't working

Comments

@marianosimone
Copy link
Contributor

marianosimone commented Sep 21, 2022

Your environment

  • ruby -v: 2.7.2p137
  • rdbg -v: 1.6.2

Describe the bug
With certain binary data in a variable, the DAP server fails to dump the frame data and crashes

To Reproduce

I originally detected this when using protobuf, as the inspect method uses interpolates its value (which is binary data) into the string that describes it.

A simple way to reproduce is:

  1. Create a file like:
class PassthroughInspect
  def initialize(data)
    @data = data
  end

  def inspect
    @data
  end
end

with_binary_data = PassthroughInspect.new([8, 200, 1].pack('CCC'))
puts("Put a breakpoint here!")
  1. Use VSCode, add a breakpoint to the last line, and start debugging
  2. Immediately after reaching the breakpoint, the session will end

Expected behavior
The debugging session shouldn't crash

Additional context
To debug this, you can add something like this to the same file you are debugging:

require 'json'

JSON.instance_eval do
  class << self
    alias unsafe_dump dump
  end

  def dump(obj, *args)
    unsafe_dump(obj, *args)
  rescue StandardError => e
    puts("There was an exception dumping the state: #{e}")
    puts("The backtrace is: #{e.backtrace&.join('\n')}")
    puts("The offending object is #{obj}")
  end
end

This shows that the problem is source sequence is illegal/malformed utf-8, and the trace is:

 <redacted>/json-2.3.1/lib/json/common.rb:430:in `generate'
 <redacted>/json-2.3.1/lib/json/common.rb:430:in `generate'
 <redacted>/json-2.3.1/lib/json/common.rb:629:in `dump'
 target.rb:11:in `dump' # this is the test file
 <redacted>/debug-1.6.2/lib/debug/server_dap.rb:206:in `send'
 <redacted>/debug-1.6.2/lib/debug/server_dap.rb:220:in `send_response'
 <redacted>/debug-1.6.2/lib/debug/server_dap.rb:441:in `respond'
 <redacted>/debug-1.6.2/lib/debug/server_dap.rb:650:in `dap_event'
 <redacted>/debug-1.6.2/lib/debug/session.rb:307:in `process_event'
 <redacted>/debug-1.6.2/lib/debug/session.rb:204:in `session_server_main'
 <redacted>/debug-1.6.2/lib/debug/session.rb:174:in `block in activate'

The problem is that the any variable in my example now has binary data as its value, and when ruby/debug tries to dump it into a String that can send over DAP, JSON complains about it not being a utf-8 string.

@ko1 ko1 added the bug Something isn't working label Oct 4, 2022
@ko1 ko1 added this to the v1.7.0 milestone Oct 4, 2022
@ko1 ko1 closed this as completed in #758 Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants