MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #17801] seg fault in read.socket #6977

Closed MichaelChirico closed 4 years ago

MichaelChirico commented 4 years ago

Created attachment 2604 [details] Simulated data for test script.

The following code is crashing R with a seg fault. I'm suspecting that there is an uncaught error return.

R version 3.4.4 (2018-03-15) -- "Someone to Lean On" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.

[Previously saved workspace restored]

> if (identical(getOption('pager'), file.path(R.home('bin'), 'pager')))
options(pager='cat') # rather take the ESS one 
options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient',
show.error.locations=TRUE)
readFromSocket <- function (port) {

+ sock <- make.socket(port=port,server=TRUE) + len <- as.integer(read.socket(sock)) + read.socket(sock,len) + }

readFromSocket(12525)

caught segfault address 0x7fff80c0f268, cause 'memory not mapped'

Traceback: 1: read.socket(sock, len) 2: readFromSocket(12525)

In this case, R is running as a server being served JSON from another process. The JSON sends an initial line with the length, which seems to execute correctly and then sends the JSON. This results in the segfault.

To simulate the other process, I use the unix command nc localhost 12525 <shortmess.txt in another window.


METADATA

MichaelChirico commented 4 years ago

Thanks. read.socket was not handling the NA maxlen you were giving it properly. It now checks that maxlen is non-negative and uses a better strategy for allocating its buffer. Fixed in R-devel (r78466) and R-patched (r78467).

[Your first read was getting a string of length 256 and as.integer produced NA for that.]


METADATA