racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
447 stars 94 forks source link

Opening a WXME File That Triggers a Contract Violation Freezes DrRacket #451

Closed shhyou closed 3 years ago

shhyou commented 3 years ago

Version

Welcome to Racket v7.9.0.900 [bc] Welcome to Racket v7.9.0.900 [cs]

(the release candidate)

Steps to Reproduce the Issue

The following WXME file triggers a contract violation error in DrRacket: color-red.rkt.tar.gz

Running this file from the command line does not trigger any error.

Expected Behavior

  1. I am expecting that opening such a file would not freeze DrRacket. However, DrRacket becomes unresponsive after trying to open this file.
  2. Racket v7.9 [bc] can open this file without any error. I am unsure if this is an issue with gui-lib.

Error Messages

$ drracket color-red.rkt
color-red: contract violation
  expected: color?
  given: '#(struct:color 100 155 0 255)
  context...:
   <RACKET>/share/pkgs/gui-lib/mrlib/image-core.rkt:1671:0: get-color-arg
   <RACKET>/share/pkgs/gui-lib/mrlib/image-core.rkt:1660:0: mode-color->brush
   <RACKET>/share/pkgs/gui-lib/mrlib/image-core.rkt:1285:0: render-np-atomic-shape
   <RACKET>/share/pkgs/gui-lib/mrlib/image-core.rkt:1156:2: loop
   <RACKET>/share/pkgs/gui-lib/mrlib/image-core.rkt:1058:0: render-image
   <RACKET>/share/pkgs/gui-lib/mrlib/image-core.rkt:426:4: compute-cached-bitmap method in image%
   <RACKET>/share/pkgs/gui-lib/mrlib/image-core.rkt:445:4: draw method in image%
   <RACKET>/share/pkgs/gui-lib/mred/private/wxme/text.rkt:5469:24: sloop
   <RACKET>/share/pkgs/gui-lib/mred/private/wxme/text.rkt:5438:16: lloop
   <RACKET>/share/pkgs/gui-lib/mred/private/wxme/text.rkt:5225:2: refresh method in text%
   <RACKET>/share/pkgs/gui-lib/mred/private/wxme/editor-canvas.rkt:648:2: redraw method in editor-canvas%
   <RACKET>/share/pkgs/gui-lib/mred/private/wxme/editor-canvas.rkt:557:2: on-paint method in editor-canvas%
   <RACKET>/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization
   <RACKET>/collects/racket/private/more-scheme.rkt:266:2: call-with-exception-handler
   <RACKET>/share/pkgs/gui-lib/mred/private/wx/common/canvas-mixin.rkt:144:4: do-on-paint method in canvas-mixin
   <RACKET>/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:435:6
   ...
rfindler commented 3 years ago

Turns out that the code that parsed the file's contents and build the editor data structures was indeed broken but the error doesn't happen until the resulting snip is drawn. So that's why DrR get so heavily wedged; the code that does that drawing is special, trusted code. The commit fixes the parser so that we don't have bogus values in the structs (and thus the drawing code won't crash anymore).