Skip to content

Commit bd95e80

Browse files
authored
Handle unknown timezone identifiers in FsTzdbProvider (#345)
1 parent 89bfca1 commit bd95e80

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/tzdb.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,19 @@ impl Tzif {
167167

168168
#[cfg(target_family = "unix")]
169169
pub fn read_tzif(identifier: &str) -> TemporalResult<Self> {
170+
// Protect from path traversal attacks
171+
if identifier.starts_with('/') || identifier.contains('.') {
172+
return Err(TemporalError::range().with_message("Ill-formed timezone identifier"));
173+
}
170174
let mut path = PathBuf::from(ZONEINFO_DIR);
171175
path.push(identifier);
172176
Self::from_path(&path)
173177
}
174178

175179
pub fn from_path(path: &Path) -> TemporalResult<Self> {
180+
if !path.exists() {
181+
return Err(TemporalError::range().with_message("Unknown timezone identifier"));
182+
}
176183
tzif::parse_tzif_file(path)
177184
.map(Into::into)
178185
.map_err(|e| TemporalError::general(e.to_string()))

0 commit comments

Comments
 (0)