]> git.sesse.net Git - plocate/commitdiff
Fix an issue where the database could be built with the wrong check_visibility flag.
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 5 Dec 2020 09:49:55 +0000 (10:49 +0100)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 5 Dec 2020 09:50:49 +0000 (10:50 +0100)
The check_visibility flag would never be set in the header, and thus be set to some
random variable instead of what the user wanted.

access_rx_cache.cpp
access_rx_cache.h
database-builder.cpp
database-builder.h
db.h
plocate-build.cpp
plocate.cpp
updatedb.cpp

index a16a1fc58f1cadc0a9a15bad663e107a8e125d5c..b6db4eaf101c9faa288e3d0ac005b946c1a68e15 100644 (file)
@@ -11,7 +11,7 @@ using namespace std;
 
 void AccessRXCache::check_access(const char *filename, bool allow_async, function<void(bool)> cb)
 {
-       if (!require_visibility) {
+       if (!check_visibility) {
                cb(true);
                return;
        }
index 80383ea6512a221e3a9baaaa87e660d143fd7582..460311dfb27279dd5a6bfed766c78ac930058408 100644 (file)
@@ -12,8 +12,8 @@ class IOUringEngine;
 
 class AccessRXCache {
 public:
-       AccessRXCache(IOUringEngine *engine, bool require_visibility)
-               : engine(engine), require_visibility(require_visibility) {}
+       AccessRXCache(IOUringEngine *engine, bool check_visibility)
+               : engine(engine), check_visibility(check_visibility) {}
        void check_access(const char *filename, bool allow_async, std::function<void(bool)> cb);
 
 private:
@@ -25,7 +25,7 @@ private:
        std::map<std::string, std::vector<PendingStat>> pending_stats;
        IOUringEngine *engine;
        std::mutex mu;
-       bool require_visibility;
+       bool check_visibility;
 };
 
 #endif  // !defined(_ACCESS_RX_CACHE_H)
index fdd637a059f05bee47be8a90367cb3f30d137faf..6e792be450202767b55eec08c869cae3b242b4a9 100644 (file)
@@ -417,7 +417,7 @@ unique_ptr<Trigram[]> create_hashtable(Corpus &corpus, const vector<uint32_t> &a
        return ht;
 }
 
-DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_size, string dictionary)
+DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_size, string dictionary, bool check_visibility)
        : outfile(outfile), block_size(block_size)
 {
        umask(0027);
@@ -456,6 +456,7 @@ DatabaseBuilder::DatabaseBuilder(const char *outfile, gid_t owner, int block_siz
        hdr.max_version = 2;
        hdr.filename_index_offset_bytes = -1;
        hdr.zstd_dictionary_length_bytes = -1;
+       hdr.check_visibility = check_visibility;
        fwrite(&hdr, sizeof(hdr), 1, outfp);
 
        if (dictionary.empty()) {
index e2c0c19f54c291d19d99edd87c47b23c48b2ac50..97188e131e3c800b16585396c9d9cdae9e2493b5 100644 (file)
@@ -101,7 +101,7 @@ private:
 
 class DatabaseBuilder {
 public:
-       DatabaseBuilder(const char *outfile, gid_t owner, int block_size, std::string dictionary);
+       DatabaseBuilder(const char *outfile, gid_t owner, int block_size, std::string dictionary, bool check_visibility);
        Corpus *start_corpus(bool store_dir_times);
        void set_next_dictionary(std::string next_dictionary);
        void set_conf_block(std::string conf_block);
diff --git a/db.h b/db.h
index 722e567076eb36551e03c56eb02db2682c834292..1670d6bc304c1e327f3bf2463dfbb5ae953cf0ac 100644 (file)
--- a/db.h
+++ b/db.h
@@ -26,7 +26,7 @@ struct Header {
        uint64_t conf_block_offset_bytes;
 
        // Only if max_version >= 2.
-       bool require_visibility;
+       bool check_visibility;
 };
 
 struct Trigram {
index 5c205aabef6d636f5c40cc009920ef61d5cdd1ea..cb765ed742a738bb91507b5fefa910a85b26ac59 100644 (file)
@@ -166,7 +166,7 @@ void do_build(const char *infile, const char *outfile, int block_size, bool plai
        }
        string dictionary = builder.train(1024);
 
-       DatabaseBuilder db(outfile, /*owner=*/-1, block_size, dictionary);
+       DatabaseBuilder db(outfile, /*owner=*/-1, block_size, dictionary, /*check_visibility=*/true);
        Corpus *corpus = db.start_corpus(/*store_dir_times=*/false);
        if (plaintext) {
                read_plaintext(infp, corpus);
index 4f88b4bd74c2ffe230052997939a1cbe30a5ffb0..c47c6480465a7f9e70472e7cbac984e3c6ddc78d 100644 (file)
@@ -107,7 +107,7 @@ Corpus::Corpus(int fd, IOUringEngine *engine)
        }
        if (hdr.max_version < 2) {
                // This too. (We ignore the other max_version 2 fields.)
-               hdr.require_visibility = true;
+               hdr.check_visibility = true;
        }
 }
 
@@ -234,7 +234,7 @@ void scan_file_block(const vector<Needle> &needles, string_view compressed,
 size_t scan_docids(const vector<Needle> &needles, const vector<uint32_t> &docids, const Corpus &corpus, IOUringEngine *engine)
 {
        Serializer docids_in_order;
-       AccessRXCache access_rx_cache(engine, corpus.get_hdr().require_visibility);
+       AccessRXCache access_rx_cache(engine, corpus.get_hdr().check_visibility);
        atomic<uint64_t> matched{ 0 };
        for (size_t i = 0; i < docids.size(); ++i) {
                uint32_t docid = docids[i];
@@ -310,7 +310,7 @@ uint64_t scan_all_docids(const vector<Needle> &needles, int fd, const Corpus &co
                }
        }
 
-       AccessRXCache access_rx_cache(nullptr, corpus.get_hdr().require_visibility);
+       AccessRXCache access_rx_cache(nullptr, corpus.get_hdr().check_visibility);
        Serializer serializer;
        uint32_t num_blocks = corpus.get_num_filename_blocks();
        unique_ptr<uint64_t[]> offsets(new uint64_t[num_blocks + 1]);
index 1be25e2d4b06cae61c7a057f520a9af8020819ad..8435a48b56f40ccaecf510913e15291050f336a9 100644 (file)
@@ -767,7 +767,7 @@ int main(int argc, char **argv)
                owner = grp->gr_gid;
        }
 
-       DatabaseBuilder db(conf_output.c_str(), owner, conf_block_size, existing_db.read_next_dictionary());
+       DatabaseBuilder db(conf_output.c_str(), owner, conf_block_size, existing_db.read_next_dictionary(), conf_check_visibility);
        db.set_conf_block(conf_block);
        Corpus *corpus = db.start_corpus(/*store_dir_times=*/true);