Skip to content

Commit 3d10a74

Browse files
authored
Fix segmentation fault in extract_from_url (#23)
2 parents 2ba121a + e21a97b commit 3d10a74

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pydomainextractor"
3-
version = "0.13.4"
3+
version = "0.13.5"
44
authors = ["Gal Ben David <[email protected]>"]
55
edition = "2021"
66
description = "A blazingly fast domain extraction library written in Rust"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pydomainextractor"
3-
version = "0.13.4"
3+
version = "0.13.5"
44
description = "A blazingly fast domain extraction library written in Rust"
55
authors = [
66
{email = "[email protected]"},

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ impl DomainExtractor {
254254
);
255255
}
256256

257+
if url_str.len() > 255 {
258+
return Err(PyValueError::new_err("url is invalid: too long"));
259+
}
257260
let mut domain_string = unsafe {
258261
DomainString::from_str_unchecked(url_str)
259262
};

tests/test_pydomainextractor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ def test_syntactic_invalid_domains(
301301
):
302302
self.domain_extractor.extract('com.')
303303

304+
def test_domain_too_long(
305+
self,
306+
):
307+
with self.assertRaises(
308+
expected_exception=ValueError,
309+
):
310+
self.domain_extractor.extract(f'{"very-long" * 255}.com')
311+
304312
def test_extract_from_url(
305313
self,
306314
):
@@ -349,6 +357,11 @@ def test_extract_from_url(
349357
):
350358
self.domain_extractor.extract_from_url('co.uk')
351359

360+
with self.assertRaises(
361+
ValueError,
362+
):
363+
self.domain_extractor.extract_from_url(f'http://{"domain" * 255}co.uk:3030/some/path')
364+
352365
self.assertEqual(
353366
first=self.domain_extractor.extract_from_url('http://www.google.com'),
354367
second={

0 commit comments

Comments
 (0)