Skip to content

bugfix: data size calculation and data range check #4

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bbiao
Copy link

@bbiao bbiao commented Aug 19, 2021

  1. Data size use two bytes to store size, so it should used data[offset] << 8 | data[offset + 1] to calculate size
  2. In some user generated ipdb database, data offset 0 has data too

1. Data size use two bytes to store size, so it should used data[offset] << 8
   | data[offset + 1] to calculate size
2. In some user generated ipdb database, data offset 0 has data too
@bbiao bbiao closed this Aug 19, 2021
@bbiao bbiao reopened this Aug 20, 2021
@bbiao
Copy link
Author

bbiao commented Aug 20, 2021

Official ipdb database has 19-bytes zero between the trie-tree node and region data, if this is a strong rules for the ipdb file format?
From the code, if go and find the NodeCound node, the search should stop.

Other programming language sdk has the same problem.


官方的IPDB数据库中,Trie-Tree节点区域和地理位置信息区域之间有19个字节的空白,不知道这是否是文件格式的强保证。
从代码逻辑上来讲,如果查询到Trie-Tree指向值为NodeCount的节点时,也应当认为查询结束。

其他语言版本的SDK也有类似问题。

@ipipdotnet
Copy link
Owner

Official ipdb database has 19-bytes zero between the trie-tree node and region data, if this is a strong rules for the ipdb file format?
From the code, if go and find the NodeCound node, the search should stop.

Other programming language sdk has the same problem.

官方的IPDB数据库中,Trie-Tree节点区域和地理位置信息区域之间有19个字节的空白,不知道这是否是文件格式的强保证。
从代码逻辑上来讲,如果查询到Trie-Tree指向值为NodeCount的节点时,也应当认为查询结束。

其他语言版本的SDK也有类似问题。

这个空白是有意放置的

@bbiao
Copy link
Author

bbiao commented Aug 23, 2021

Official ipdb database has 19-bytes zero between the trie-tree node and region data, if this is a strong rules for the ipdb file format?
From the code, if go and find the NodeCound node, the search should stop.
Other programming language sdk has the same problem.
官方的IPDB数据库中,Trie-Tree节点区域和地理位置信息区域之间有19个字节的空白,不知道这是否是文件格式的强保证。
从代码逻辑上来讲,如果查询到Trie-Tree指向值为NodeCount的节点时,也应当认为查询结束。
其他语言版本的SDK也有类似问题。

这个空白是有意放置的

假设我们的数据里有指向这块空白区域的节点,那查询流程并不会结束,然后会从节点0(因为是空白读出来下一跳是0,无论左右节点)重新搜索。

所以如果把这个空白当作预留,代码里遇到NodeCount这个大小的Node时,也应该结束,这样代码的容错性会好一些。

不知道你们的设计上是否还有其他用意,仅从容错的角度来看,修改搜索终止条件会更好一些。

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.

2 participants