Skip to content

Commit

Permalink
Do not return input from a connection with encoding conversion after
Browse files Browse the repository at this point in the history
encountering invalid bytes (restores documented behavior).


git-svn-id: https://svn.r-project.org/R/trunk@85707 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Dec 19, 2023
1 parent 8c4da14 commit bf6d110
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/main/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,7 @@ int dummy_fgetc(Rconnection con)
{
if(con->inconv) {
Rboolean checkBOM = FALSE, checkBOM8 = FALSE;
con->EOF_signalled = FALSE; /* e.g. for a non-blocking connection; PR#18555 */
while(con->navail <= 0) {
/* Probably in all cases there will be at most one iteration
of the loop. It could iterate multiple times only if the input
encoding could have \r or \n as a part of a multi-byte coded
character.
*/
unsigned int i, inew = 0;
char *p, *ob;
const char *ib;
Expand All @@ -572,7 +566,10 @@ int dummy_fgetc(Rconnection con)
int c = (con->buff)
? buff_fgetc(con)
: con->fgetc_internal(con);
if(c == R_EOF){ con->EOF_signalled = TRUE; break; }
if(c == R_EOF)
/* Do not set EOF_signalled, because subsequent reads from
a non-blocking connections may succeed (PR18555). */
break;
*p++ = (char) c;
con->inavail++;
inew++;
Expand Down Expand Up @@ -612,7 +609,9 @@ int dummy_fgetc(Rconnection con)
warning(_("invalid input found on input connection '%s'"),
con->description);
con->inavail = 0;
if (con->navail == 0) return R_EOF;
/* Set to prevent reading any more bytes from input,
possibly those following the invalid bytes currently
encountered. */
con->EOF_signalled = TRUE;
}
}
Expand Down

0 comments on commit bf6d110

Please sign in to comment.