futureverse / marshal

[PROTOTYPE] R package: marshal - Framework to Marshal Objects to be Used in Another R Processes
https://marshal.futureverse.org/
Other
15 stars 1 forks source link

marshal: turn connections into invalid connections #3

Open HenrikBengtsson opened 2 years ago

HenrikBengtsson commented 2 years ago

For example, if we detect a connection with index K, we can change its index to -1. If the connection is never used, all is fine, and if it's used it'll trigger a run-time error.

The background is that R does not protect against using connections in other R sessions. This should ideally be fixed in R itself, cf. https://github.com/HenrikBengtsson/Wishlist-for-R/issues/81

HenrikBengtsson commented 2 years ago

Gist:

> con <- rawConnection(raw(), open = "w")
> con
A connection with                           
description "raw()"        
class       "rawConnection"
mode        "w"            
text        "binary"       
opened      "opened"       
can read    "no"           
can write   "yes"          
> str(con)
 'rawConnection' int 5
 - attr(*, "conn_id")=<externalptr> 

Invalidate above connection:

> con[1] <- -1L
> str(con)
 'rawConnection' int -1
 - attr(*, "conn_id")=<externalptr> 
> con
A connection, specifically, 'rawConnection', but invalid.