Skip to content

Commit e00e792

Browse files
gyscosclaude
andcommitted
zstd-safe: bind init_using_{c,d}dict's dictionary borrow to the context
Like the with_prepared_dictionary constructors fixed for #365, the deprecated CCtx::init_using_cdict and DCtx::init_using_ddict took the dictionary as &X<'b> with only 'b: 'a, so the reference itself could end while the context still pointed at the dictionary. Take &'a X<'b>, as ref_cdict and ref_ddict already do. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-QYXWIMNZ. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MxSMUdwqoQ3qm6UF82MgZD
1 parent d34502a commit e00e792

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎zstd-safe/src/lib.rs‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,22 @@ impl<'a> CCtx<'a> {
533533
}
534534

535535
/// Wraps the `ZSTD_initCStream_usingCDict()` function.
536+
///
537+
/// Dictionary must outlive the context.
538+
///
539+
/// ```compile_fail,E0515
540+
/// # #![allow(deprecated)]
541+
/// fn compressor() -> zstd_safe::CCtx<'static> {
542+
/// let cdict = zstd_safe::CDict::create(b"dictionary", 3);
543+
/// let mut cctx = zstd_safe::CCtx::create();
544+
/// cctx.init_using_cdict(&cdict).unwrap();
545+
/// cctx // `cdict` would be dropped while `cctx` still points at it.
546+
/// }
547+
/// ```
536548
#[cfg(feature = "experimental")]
537549
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
538550
#[deprecated(note = "Use reset and ref_cdict instead.")]
539-
pub fn init_using_cdict<'b>(&mut self, cdict: &CDict<'b>) -> SafeResult
551+
pub fn init_using_cdict<'b>(&mut self, cdict: &'a CDict<'b>) -> SafeResult
540552
where
541553
'b: 'a, // Dictionary outlives the stream.
542554
{
@@ -1278,10 +1290,22 @@ impl<'a> DCtx<'a> {
12781290
}
12791291

12801292
/// Wraps the `ZSTD_initDStream_usingDDict()` function.
1293+
///
1294+
/// Dictionary must outlive the context.
1295+
///
1296+
/// ```compile_fail,E0515
1297+
/// # #![allow(deprecated)]
1298+
/// fn decompressor() -> zstd_safe::DCtx<'static> {
1299+
/// let ddict = zstd_safe::DDict::create(b"dictionary");
1300+
/// let mut dctx = zstd_safe::DCtx::create();
1301+
/// dctx.init_using_ddict(&ddict).unwrap();
1302+
/// dctx // `ddict` would be dropped while `dctx` still points at it.
1303+
/// }
1304+
/// ```
12811305
#[cfg(feature = "experimental")]
12821306
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
12831307
#[deprecated(note = "Use reset and ref_ddict instead.")]
1284-
pub fn init_using_ddict<'b>(&mut self, ddict: &DDict<'b>) -> SafeResult
1308+
pub fn init_using_ddict<'b>(&mut self, ddict: &'a DDict<'b>) -> SafeResult
12851309
where
12861310
'b: 'a,
12871311
{

0 commit comments

Comments
 (0)