Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read unsigned integers in WKBReader #392

Merged
merged 1 commit into from
Jan 29, 2021
Merged

Conversation

dbaston
Copy link
Member

@dbaston dbaston commented Jan 29, 2021

OGC WKB spec specifies that the integers are unsigned. Use of signed
integers is probably a carryover from Java, which does not have unsigned
integers. Clear type conversion warnings in WKBReader and use C++11
int64_t type.

OGC WKB spec specifies that the integers are unsigned. Use of signed
integers is probably a carryover from Java, which does not have unsigned
integers. Clear type conversion warnings in WKBReader and use C++11
int64_t type.
@pramsey
Copy link
Member

pramsey commented Jan 29, 2021

I guess the fix for OOM is still to come? It looks like CoordinateSequence reading

https://github.com/dbaston/libgeos/blob/wkbreader-unsigned/src/io/WKBReader.cpp#L431

starts by allocating a new CoordinateArraySequence with a (size, dims) constructor

https://github.com/dbaston/libgeos/blob/wkbreader-unsigned/src/geom/CoordinateArraySequence.cpp#L36-L41

which initializes the underlying vector using the (count) constructor

https://en.cppreference.com/w/cpp/container/vector/vector

Which does

"4) Constructs the container with count default-inserted instances of T. No copies are made."

So if you feed a degenerate WKB linestring with a 2B count, you can get GEOS to allocate the whole 2B before you actually try and read them and find the end on the input stream.

@dr-jts
Copy link
Contributor

dr-jts commented Jan 29, 2021

I guess the fix for OOM is still to come?

JTS has fixed this in PR 675, at least for the case when the size of the input byte sequence is known. It computes an upper bound on the value of all num* fields in the WKB, based on the size of the input. The num* fields are then checked against that limit.

@dbaston
Copy link
Member Author

dbaston commented Jan 29, 2021

I guess the fix for OOM is still to come?

Right, this is unrelated to OOM.

@strk strk merged commit d28547c into libgeos:master Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants