Commit Graph

11 Commits

Author SHA1 Message Date
Zeyi Fan
9277617d1e fix double free in cdatapack
Summary:
Mercurial recently started to generate empty pack files (`0x01`). This will cause this check to fail:

diffusion/FBS/browse/master/fbcode/scm/hg/lib/cdatapack/cdatapack.c;2c4197d003ed906dd8eaf70fbb04aa53440ce681$314-319

This will subsequently result as a double-free error between these two:

**In `error_cleanup`**

diffusion/FBS/browse/master/fbcode/scm/hg/lib/cdatapack/cdatapack.c;2c4197d003ed906dd8eaf70fbb04aa53440ce681$387-389

**In `close_datapack`**

diffusion/FBS/browse/master/fbcode/scm/hg/lib/cdatapack/cdatapack.c;2c4197d003ed906dd8eaf70fbb04aa53440ce681$401

This diff will fix this bug.

Differential Revision: D14759374

fbshipit-source-id: 06f192513a935740c2142b5a2baac87a28903496
2019-04-03 21:13:13 -07:00
Wez Furlong
31bcfbe58e hg: disable check-code tests for C code
Summary:
They're actively fighting against the clang-format config
and don't have an auto-fix.

Reviewed By: quark-zju

Differential Revision: D8283622

fbshipit-source-id: 2de45f50e6370a5ed14915c6ff23dc843ff14e8a
2018-06-05 19:21:43 -07:00
Adam Simpkins
641bac8427 improve cdatapack fanout table calculation
Summary:
Refactor the cdatapack logic that computes the fanout table.  This more
accurately computes the correct ranges to bisect for each fanout table entry.

This fixes an off-by-one error setting end_index in most buckets that caused
it to search a slightly larger bisection range than necessary.

This also fixes the code to accurately compute which buckets do not have any
nodes, and sets a (start, end) range of (1, 0) for these buckets, causing
find() to avoid having to search anything in these cases.

Reviewed By: quark-zju

Differential Revision: D8131019

fbshipit-source-id: 70d6d0f2e1d900a2df27b64f3a38f114d301be0d
2018-05-30 18:54:19 -07:00
Adam Simpkins
2ea8028d14 fix a bug in cdatapack fanout table calculation
Summary:
If all of the nodes in a datapack file start with the same byte value,
the cdatapack code computed the fanout table incorrectly.  If this byte value
was anything other than 0x00 it would only be able to find the last node in
the pack, and would not be able to find any other nodes.

This fixes the code to compute the fanout table correctly in this case.

Reviewed By: quark-zju

Differential Revision: D8131020

fbshipit-source-id: 84e49befc5776cff96831f6120194466d9c80b35
2018-05-30 13:47:50 -07:00
Adam Simpkins
490247285c update open_datapack() to reject empty pack files
Summary:
Update the open_datapack() function to fail with an DATAPACK_HANDLE_CORRUPT
error if the index file contains a valid header but no index entries.

Previously open_datapack() would succeed, but it would incorrectly read past
the end of the mmapped data when trying to find entries.

The python code never generates empty pack files, so this behavior change
should not affect any legitimate pack files.

Reviewed By: quark-zju

Differential Revision: D8131018

fbshipit-source-id: a07eac9048314c9974cae0f98efaf8a4a383d966
2018-05-25 18:03:27 -07:00
Adam Simpkins
7233f0dfb1 update cdatapack utilities to check open success
Summary:
Update cdatapack_dump and cdatapack_get to check the return value from
`open_datapack()` to confirm if they actually successfully opened the file.

Previously these programs would segfault if invoked with a non-existent path.

Reviewed By: quark-zju

Differential Revision: D8131017

fbshipit-source-id: 90800de57430efd176b8e71fa84161f7b288e375
2018-05-24 11:30:48 -07:00
Kostia Balytskyi
0ef59877cd hg: some portability fixes to py-cdatapack.h
Summary:
1. Variable Length Arrays are not supported by MSVC, but since this is a C++ code, we can just use heap allocation
2. Replacing `inet` with portability version

Depends on D7196403

Reviewed By: quark-zju

Differential Revision: D7196605

fbshipit-source-id: a0d88b6e06f255ef648c0b35a99b42ba3bee538a
2018-04-13 21:51:24 -07:00
Kostia Balytskyi
62ecc73818 hg: make sure platform_madvise_away returns -1 on Windows
Summary:
On the other two platforms we return the result of `madvise`, so let's return -1,
as this is the error return value of `madvise` on POSIX.

Reviewed By: quark-zju

Differential Revision: D6979093

fbshipit-source-id: 7c715eb459aaad6c21fae6e346e8650211649182
2018-04-13 21:51:11 -07:00
Kostia Balytskyi
c85791785b hg: build cdatapack on Windows
Summary: Seems to be working now.

Reviewed By: quark-zju

Differential Revision: D6970927

fbshipit-source-id: e67753d811819015282f47fcbdfbb263d85f054f
2018-04-13 21:51:10 -07:00
Kostia Balytskyi
5d1139f87d hg: move defines out of struct definition in cdatapack.c
Summary: The current location of these defines is really odd and does not work with the current version of `PACKEDSTRUCT` macro expansion (it expands everything in the same line, therefore `#defines` are inline, which fails to compile.

Reviewed By: quark-zju

Differential Revision: D6970926

fbshipit-source-id: ed01042760fa729004e159b492cf67a4afd25923
2018-04-13 21:51:10 -07:00
Durham Goode
eb099b7fe1 cdatapack: move to lib/
Summary:
This moves the cdatapack code to the new lib/ directory and adds it to the main
setup.py.

Test Plan: hg purge --all && make local && cd tests && ./run-tests.py -S -j 48

Reviewers: #mercurial

Differential Revision: https://phabricator.intern.facebook.com/D6677491
2018-01-08 17:55:53 -08:00