rust-lang / rust-lang/rust

Bad parsing in module-level comments when there is /* in a verbatim string

Open
#157,034 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

I tried this code:

/*!
When processing an SVG, librsvg will only load referenced files if
they are in the same directory as the base file, or in a
subdirectory of it.  That is, if the base file is
`/foo/bar/baz.svg`, then librsvg will only try to load referenced
files (from SVG's `<image>` element, for example, or from content
included through XML entities) if those files are in `/foo/bar/*`
or in `/foo/bar/*/.../*`.  This is so that malicious SVG documents
cannot include files that are in a directory above.
*/

fn main() {
    todo!()
}

playground link - https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=304576253624fa7fdaad266ae7d98a3c

I expected to see this happen: no compilation errors.

Instead, this happened: The code above is a shortened section of librsvg/rsvg/src/lib.rs. I get this compilation error:

error[E0758]: unterminated block doc-comment
   --> rsvg/src/lib.rs:1:1
    |
  1 |   /*!
    |   ^-
    |   |
    |  _unterminated block doc-comment
    | |
  2 | | Load and render SVG images into Cairo surfaces.
  3 | |
  4 | | This crate can load SVG images and render them to Cairo surfaces,
...   |
 91 | | or in `/foo/bar/*/.../*`.  This is so that malicious SVG documents
    | |                      -- ...as last nested comment starts here, maybe you want to close this instead?
...   |
140 | | */    
    | | -- ...and last nested comment terminates here.
...   |
275 | |     pub use crate::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
276 | | }
    | |__^

I think the parser is getting confused about /foo/bar/*/.../* and thinks that the /* in there are comment delimiters, when they are in fact part of the verbatim string.

(... apologies if I'm getting my syntax completely wrong)

Meta

rustc --version --verbose:

rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3

This happens in the nightly playground, too.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue in the linked Rust Playground using the module-level block comment and the /foo/bar/*/.../* text. Investigate Rust's parsing of block documentation comments and verbatim strings; the fix is complete when this example compiles without the unterminated block doc-comment error and the behavior is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.