Bug 15813 - writeLines hangs with locale==C if writing special characters. infinite warnings fill up disk
Summary: writeLines hangs with locale==C if writing special characters. infinite warni...
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: I/O (show other bugs)
Version: R 3.1.0
Hardware: x86_64/x64/amd64 (64-bit) OS X Mavericks
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-05-29 15:16 UTC by Dan Tenenbaum
Modified: 2017-03-17 17:24 UTC (History)
3 users (show)

See Also:


Attachments
reproduces the bug. contains non-ascii characters (12.97 KB, text/html)
2014-05-29 15:16 UTC, Dan Tenenbaum
Details
Proposed patch (382 bytes, patch)
2017-03-16 15:34 UTC, Mikko Korpela
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Tenenbaum 2014-05-29 15:16:50 UTC
Created attachment 1608 [details]
reproduces the bug. contains non-ascii characters

If I start R as follows:

LANG= R

and then run:

x = paste(readLines('a.html'), collapse = '\n')
con = file(tempfile(), 'w', encoding = 'UTF-8')
writeLines(x, con) 

R will hang. If I hit control-C I see many identical warnings. In practice these warnings were filling up the hard drive.

I realize this is a corner case and in fact the machine was misconfigured, it should have had a UTF-8-based locale. But the consequences were severe enough (filling up the hard drive) that I report it.

Thanks.
Comment 1 Mikko Korpela 2017-03-16 15:34:57 UTC
Created attachment 2236 [details]
Proposed patch

I think the attached patch solves the issue. With the patch applied, 'writeLines(x, con)' finishes with one warning. The resulting file is the same as without the patch, i.e. truncated at the invalid byte.

Tested with "R Under development (unstable) (2017-03-16 r72358)" on Ubuntu 14.04.5 LTS (iconv is "glibc 2.19") and OS X 10.7.5 (iconv is "GNU libiconv 1.15").
Comment 2 Tomas Kalibera 2017-03-17 17:24:56 UTC
Thanks, fixed in 72361.