drolbr / Overpass-API

A database engine to query the OpenStreetMap data.
http://overpass-api.de
GNU Affero General Public License v3.0
692 stars 90 forks source link

File_Blocks_Index: incomplete void blocks written back to disk? #664

Closed mmd-osm closed 2 years ago

mmd-osm commented 2 years ago

File_Blocks_Index destructor has some code to write back void blocks to disk:

  // Write void blocks
  Void_Pointer< uint8 > void_index_buf(void_blocks.size() * 8);
  std::pair< uint32, uint32 >* it_ptr = (std::pair< uint32, uint32 >*)(void_index_buf.ptr);
  for (std::vector< std::pair< uint32, uint32 > >::const_iterator it(void_blocks.begin());
      it != void_blocks.end(); ++it)
    *(it_ptr++) = *it;

  try
  {
    Raw_File void_file(empty_index_file_name, O_RDWR|O_TRUNC, S_666,
               "File_Blocks_Index::~File_Blocks_Index::5");
    void_file.write(void_index_buf.ptr, void_blocks.size()*sizeof(uint32),
            "File_Blocks_Index::~File_Blocks_Index::6");
  }
  catch (File_Error e) {}

https://github.com/drolbr/Overpass-API/blob/minor_issues/src/template_db/file_blocks_index.h#L375-L389

void_index_buf is created with enough space for some void_blocks.size() pairs of uint32. However, when writing this buffer to the file system, sizeof(uint32) is used instead of sizeof(std::pair< uint32, uint32 >).

It seems that half of the void_blocks aren't written back to disk.

I think this is a bug, but wanted to double check, if that's really the case.

drolbr commented 2 years ago

I can confirm that this is indeed a bug.

I is highly likely that is has no functional effect because it marks unused blocks falsely as used, not the other way round. But this should be fixed nonetheless.