Skip to content

Caught segfault setting an existing attribute that is a namespace #253

@nuest

Description

@nuest

Issue Description and Expected Result

I override an existing namespace definition on a document, so I expect the existing definition to be overwritten just like normal attributes, but there is a segfault.

Reproducible Example

> library("xml2")
> doc <- xml2::xml_new_root("the_root")
> xml2::xml_set_attr(doc, "normal", "works")
> xml2::xml_set_attr(doc, "normal", "works")
> xml2::xml_set_attr(doc, "normal", "works_still")
> doc
{xml_document}
<the_root normal="works_still">
> xml2::xml_set_attr(doc, "xmlns:thens", "http://a/namespace")
> doc
{xml_document}
<the_root normal="works" xmlns:thens="http://a/namespace">
> xml2::xml_set_attr(doc, "xmlns:thens", "http://a/namespace")

 *** caught segfault ***
address 0x18, cause 'memory not mapped'

Traceback:
 1: node_set_attr(x$node, name = attr, nsMap = ns, value)
 2: `xml_attr<-.xml_node`(x = `*tmp*`, attr = attr, ns = ns, value = value)
 3: `xml_attr<-`(x = `*tmp*`, attr = attr, ns = ns, value = value)
 4: xml_set_attr.xml_node(doc, "xmlns:thens", "http://a/namespace")
 5: xml2::xml_set_attr(doc, "xmlns:thens", "http://a/namespace")

This also happens when using xml2::set_attrs(..) <-

> xml2::xml_attrs(doc) <- c("one" = 1, "two" = 2, "xmlns:test" = "http://ns")
> doc
{xml_document}
<the_root one="1" two="2" xmlns:test="http://ns">
> xml2::xml_attrs(doc) <- c("one" = 1, "xmlns:test" = "http://another_ns")

 *** caught segfault ***
address 0x18, cause 'memory not mapped'

Traceback:
 1: node_set_attr(x$node, name = attr, nsMap = ns, value)
 2: `xml_attr<-.xml_node`(`*tmp*`, attr, ns, value = val)
 3: `xml_attr<-`(`*tmp*`, attr, ns, value = val)
 4: (function (attr, val) {    xml_attr(x, attr, ns) <- val})(attr = dots[[1L]][[2L]], dots[[2L]][[2L]])
 5: mapply(FUN = f, ..., SIMPLIFY = FALSE)
 6: Map(function(attr, val) {    xml_attr(x, attr, ns) <- val}, attr = c(existing, new), value[c(existing, new)])
 7: `xml_attrs<-.xml_node`(`*tmp*`, value = c(one = "1", `xmlns:test` = "http://another_ns"))
 8: xml2::`xml_attrs<-`(`*tmp*`, value = c(one = "1", `xmlns:test` = "http://another_ns"))

Session Info
devtools::session_info() # Paste output belowSession info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 os       Ubuntu 18.04.2 LTS          
 system   x86_64, linux-gnu           
 ui       X11                         
 language en_GB:en                    
 collate  en_GB.UTF-8                 
 ctype    en_GB.UTF-8                 
 tz       Europe/Berlin               
 date     2019-05-03Packages ───────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.0)
 backports     1.1.4   2019-04-10 [1] CRAN (R 3.6.0)
 callr         3.2.0   2019-03-15 [1] CRAN (R 3.6.0)
 cli           1.1.0   2019-03-19 [1] CRAN (R 3.6.0)
 crayon        1.3.4   2017-09-16 [1] CRAN (R 3.6.0)
 desc          1.2.0   2018-05-01 [1] CRAN (R 3.6.0)
 devtools      2.0.2   2019-04-08 [1] CRAN (R 3.6.0)
 digest        0.6.18  2018-10-10 [1] CRAN (R 3.6.0)
 fs            1.2.7   2019-03-19 [1] CRAN (R 3.6.0)
 glue          1.3.1   2019-03-12 [1] CRAN (R 3.6.0)
 magrittr      1.5     2014-11-22 [1] CRAN (R 3.6.0)
 memoise       1.1.0   2017-04-21 [1] CRAN (R 3.6.0)
 pkgbuild      1.0.3   2019-03-20 [1] CRAN (R 3.6.0)
 pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.6.0)
 prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.6.0)
 processx      3.3.0   2019-03-10 [1] CRAN (R 3.6.0)
 ps            1.3.0   2018-12-21 [1] CRAN (R 3.6.0)
 R6            2.4.0   2019-02-14 [1] CRAN (R 3.6.0)
 Rcpp          1.0.1   2019-03-17 [1] CRAN (R 3.6.0)
 remotes       2.0.4   2019-04-10 [1] CRAN (R 3.6.0)
 rlang         0.3.4   2019-04-07 [1] CRAN (R 3.6.0)
 rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.6.0)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.0)
 testthat      2.1.1   2019-04-23 [1] CRAN (R 3.6.0)
 usethis       1.5.0   2019-04-07 [1] CRAN (R 3.6.0)
 withr         2.1.2   2018-03-15 [1] CRAN (R 3.6.0)
 xml2        * 1.2.0   2018-01-24 [1] CRAN (R 3.6.0)

[1] /home/daniel/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions