Bug 15028 - [PATCH] format string bug causes truncated output in printVector
[PATCH] format string bug causes truncated output in printVector
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: I/O
R-devel (trunk)
x86_64/x64/amd64 (64-bit) Linux
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-08-25 07:48 UTC by Murray Stokely
Modified: 2014-02-16 11:41 UTC (History)
2 users (show)

See Also:


Attachments
PATCH to fix the format string causing this bug. (1.58 KB, application/octet-stream)
2012-08-25 07:48 UTC, Murray Stokely
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Murray Stokely 2012-08-25 07:48:15 UTC
Created attachment 1365 [details]
PATCH to fix the format string causing this bug.

For named vectors with long names, it is possible to make R print truncated/erroneous values for numeric and integer vectors.

For example, this 3-line snippet illustrates the bug :

x <- c(255, 1000, 30000)
names(x) <- list(paste(rep("a", 1002), collapse=""),
                   paste(rep("b", 1002), collapse=""),
                   paste(rep("c", 1002), collapse=""))
x

The strings of the list values are built by format strings with widths set according to the width of the names, but then they are used with snprintf limited to a hardcoded 1000 byte constant, NB.  The format specifier widths should use the minimum of this constant -1 or the width of the names to fix the bug.  Patch attached, or available from :

http://people.freebsd.org/~murray/patches/R-print-truncate-bug.diff

platform       x86_64-unknown-linux-gnu                          
arch           x86_64                                            
os             linux-gnu                                         
system         x86_64, linux-gnu                                 
status         Under development (unstable)                      
major          2                                                 
minor          16.0                                              
year           2012                                              
month          08                                                
day            24                                                
svn rev        60410                                             
language       R                                                 
version.string R Under development (unstable) (2012-08-24 r60410)
nickname       Unsuffered Consequences
Comment 1 Martin Maechler 2012-08-27 13:39:40 UTC
Thank you very much for the simple reproducible example and the patch.
Applied that and added a regression test, basically from your example.
Comment 2 Jackie Rosen 2014-02-16 11:41:45 UTC
(spam comment removed)