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

struct contracts do not protect reflective operations through struct-info #2359

Open
lexi-lambda opened this issue Nov 6, 2018 · 0 comments

Comments

@lexi-lambda
Copy link
Member

lexi-lambda commented Nov 6, 2018

As reported by @LiberalArtist on the mailing list, struct contracts can be subverted if you have a sufficiently powerful inspector:

#lang racket

(module s racket
  (provide (contract-out [struct must-be-integer ([v integer?])]))
  (struct must-be-integer (v)))

(require racket/runtime-path)

(define-runtime-module-path-index s-mpi '(submod "." s))

(define-values [struct:must-be-integer must-be-integer must-be-integer-v]
  (parameterize ([current-inspector (make-inspector)])
    (values (dynamic-require s-mpi 'struct:must-be-integer)
            (dynamic-require s-mpi 'must-be-integer)
            (dynamic-require s-mpi 'must-be-integer-v))))

; Succeeds, but shouldn’t!
((struct-type-make-constructor struct:must-be-integer) "not an integer")

; Also succeeds, but shouldn’t!
(define-values [struct:must-be-integer* skipped?] (struct-info (must-be-integer 1)))
((struct-type-make-constructor struct:must-be-integer*) "not an integer")

This could be a source of unsoundness in Typed Racket, as reported in racket/typed-racket#787.

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

No branches or pull requests

1 participant