Skip to content

Commit

Permalink
Merge pull request #21 from agrenott/dev
Browse files Browse the repository at this point in the history
Fix node IDs overflow
  • Loading branch information
agrenott authored Jun 2, 2023
2 parents d40a978 + d76e803 commit 0aefe64
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ name = "python"

[[analyzers]]
name = "test-coverage"
enabled = true
enabled = false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![types - Mypy](https://img.shields.io/badge/types-Mypy-blue.svg)](https://github.com/python/mypy)
[![DeepSource](https://deepsource.io/gh/agrenott/pyhgtmap.svg/?label=active+issues&show_trend=true&token=2WJPDv60DJYqaFeVT85eTdGE)](https://deepsource.io/gh/agrenott/pyhgtmap/?ref=repository-badge)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/1251b91e12da4329bd09856d526c91b3)](https://app.codacy.com/gh/agrenott/pyhgtmap/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Maintainability](https://api.codeclimate.com/v1/badges/0af92f6750f1bc0840a3/maintainability)](https://codeclimate.com/github/agrenott/pyhgtmap/maintainability)
[![Maintainability](https://api.codeclimate.com/v1/badges/96551164b79ce7e76500/maintainability)](https://codeclimate.com/github/agrenott/pyhgtmap/maintainability)

pyhgtmap is a fork of the original ![phyghtmap](http://katze.tfiu.de/projects/phyghtmap/) tool,
which doesn't seem to be maintained anymore.
Expand Down
4 changes: 2 additions & 2 deletions pyhgtmap/hgt/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def __init__(
options (optparse options): general options
"""
self.next_node_id: Synchronized = cast(
Synchronized, multiprocessing.Value("i", node_start_id)
Synchronized, multiprocessing.Value("L", node_start_id)
)
self.next_way_id: Synchronized = cast(
Synchronized, multiprocessing.Value("i", way_start_id)
Synchronized, multiprocessing.Value("L", way_start_id)
)
self.available_children = multiprocessing.Semaphore(nb_jobs)
self.parallel: bool = nb_jobs > 1
Expand Down
18 changes: 18 additions & 0 deletions tests/hgt/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,21 @@ def test_get_osm_output_single_output(default_options: SimpleNamespace) -> None:
default_options, ["file1.hgt"], (0, 1, 2, 3)
)
assert output1 is output2

@staticmethod
def test_node_id_overflow(default_options: SimpleNamespace) -> None:
# Ensure node ID doesn't overflow limit of int32
processor = HgtFilesProcessor(
1, node_start_id=2147483647, way_start_id=200, options=default_options
)
assert processor.get_and_inc_counter(processor.next_node_id, 1) == 2147483647
assert processor.get_and_inc_counter(processor.next_node_id, 1) == 2147483648

@staticmethod
def test_way_id_overflow(default_options: SimpleNamespace) -> None:
# Ensure way ID doesn't overflow limit of int32
processor = HgtFilesProcessor(
1, node_start_id=100, way_start_id=2147483647, options=default_options
)
assert processor.get_and_inc_counter(processor.next_way_id, 1) == 2147483647
assert processor.get_and_inc_counter(processor.next_way_id, 1) == 2147483648
23 changes: 23 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,29 @@ def test_produce_pbf(
# Check file size to ensure there's no major drop in efficiency (compression, dense encoding)
assert os.stat(osm_file_name).st_size < 420

@staticmethod
def test_node_id_overflow(
tile_contours: TileContours,
elev_classifier,
bounding_box: Tuple[float, float, float, float],
) -> None:
with tempfile.TemporaryDirectory() as tempdir:
osm_file_name = os.path.join(tempdir, "output.osm.pbf")
osm_output = pbfUtil.Output(
osm_file_name,
osmVersion=0.6,
pyhgtmap_version="123",
bbox=bounding_box,
elevClassifier=elev_classifier,
)
start = 2147483647
next_node_id, ways = osm_output.write_nodes(
tile_contours, ' time="some time"', start, 0.6
)

# Check int32 boundary has been passed without issue
assert next_node_id == 2147483655


class TestOutputO5m:
@staticmethod
Expand Down

0 comments on commit 0aefe64

Please sign in to comment.