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

WITH_ZCHUNK macro affects ABI #298

Closed
ppisar opened this issue Feb 12, 2024 · 1 comment · Fixed by #299
Closed

WITH_ZCHUNK macro affects ABI #298

ppisar opened this issue Feb 12, 2024 · 1 comment · Fixed by #299

Comments

@ppisar
Copy link
Contributor

ppisar commented Feb 12, 2024

DNF5 was asked to drop a useless dependency on zchunk rpm-software-management/dnf5#1233 because it delegates all zchunk work to librepo. However it turned out that struct LrDownloadTarget ABI defined in <librepo/downloadtarget.h> changes with WITH_ZCHUNK macro.

More over, if the macro is defined, <zck.h> is included albeit librepo-devel RPM package does not depend on zchunk-devel.

All that pushes librepo internals to it users, e.g. to DNF5, and makes the build chain more error prone because the whole aplication stack needs to keep WITH_ZCHUNK in synchronization.

I would appreciate isolating librepo ABI from WITH_ZCHUNK macro.

@ppisar
Copy link
Contributor Author

ppisar commented Feb 12, 2024

I forgot to notice that the biggest mistake of the current code is that compiled librepo has struct LrDownloadTarget of a certain size, but applications including librepo header files without matching WITH_ZCHUNK will see struct LrDownloadTarget of a different size. This can lead to memory corruptions and segfaults.

ppisar added a commit to ppisar/librepo that referenced this issue Feb 12, 2024
If librepo was built with -DWITH_ZCHUNK=ON but an application included
<librepo/librepo.h> without defining -DWITH_ZCHUNK, struct
LrDownloadTarget mismatched. The same problem happened vice versa.
Following the correct ABI was a burden for librepo applications and
a mistake there lead to a memory corruption.

This patch replaces the WITH_ZCHUNK macros in the public header files
with a constant so that the installed header files do not depend on
the macro and always match the installed library.

This patch also adds a missing RPM dependency on zchunk-devel to
librepo-devel if built with enabled zchunk. (Some header files include
<zck.h>.)

An implementation note: CMakeLists.txt appends the header search paths
with both a top-level build direcory as well as with a librepo
subdirectory. The latter is for "util.h" inclusions from the C files,
the former is for <librepo/util.h> inclusions from other librepo header
files. Without the former a C preprocesor would use already installed
<librepo/util.h>. We do not want to infect the being built library
with old and possible nonmatching system header files.

Fixes: rpm-software-management#298
ppisar added a commit to ppisar/librepo that referenced this issue Feb 12, 2024
If librepo was built with -DWITH_ZCHUNK=ON but an application included
<librepo/librepo.h> without defining -DWITH_ZCHUNK, struct
LrDownloadTarget mismatched. The same problem happened vice versa.
Following the correct ABI was a burden for librepo applications and
a mistake there lead to a memory corruption.

This patch replaces the WITH_ZCHUNK macros in the public header files
with a constant so that the installed header files do not depend on
the macro and always match the installed library.

This patch also adds a missing RPM dependency on zchunk-devel to
librepo-devel if built with enabled zchunk. (Some header files include
<zck.h>.)

An implementation note: CMakeLists.txt appends the header search paths
with both a top-level build direcory as well as with a librepo
subdirectory. The latter is for "util.h" inclusions from the C files,
the former is for <librepo/util.h> inclusions from other librepo header
files. Without the former a C preprocesor would use already installed
<librepo/util.h>. We do not want to infect the being built library
with old and possible nonmatching system header files.

Fixes: rpm-software-management#298
ppisar added a commit to ppisar/librepo that referenced this issue Feb 12, 2024
If librepo was built with -DWITH_ZCHUNK=ON but an application included
<librepo/librepo.h> without defining -DWITH_ZCHUNK, struct
LrDownloadTarget mismatched. The same problem happened vice versa.
Following the correct ABI was a burden for librepo applications and
a mistake there could lead to a memory corruption.

This patch replaces the WITH_ZCHUNK macros in the public header files
with a constant so that the installed header files do not depend on
the macro and always match the installed library.

This patch also adds a missing RPM dependency on zchunk-devel to
librepo-devel if built with enabled zchunk. (Some header files include
<zck.h>.)

An implementation note: CMakeLists.txt appends the header search paths
with both a top-level build direcory as well as with a librepo
subdirectory. The latter is for "util.h" inclusions from the C files,
the former is for <librepo/util.h> inclusions from other librepo header
files. Without the former a C preprocesor would use already installed
<librepo/util.h>. We do not want to infect the being built library
with old and possible nonmatching system header files.

Fixes: rpm-software-management#298
ppisar added a commit to ppisar/librepo that referenced this issue Feb 12, 2024
If librepo was built with -DWITH_ZCHUNK=ON but an application included
<librepo/librepo.h> without defining -DWITH_ZCHUNK, struct
LrDownloadTarget mismatched. The same problem happened vice versa.
Following the correct ABI was a burden for librepo applications and
a mistake there could lead to a memory corruption.

This patch replaces the WITH_ZCHUNK macros in the public header files
with a constant so that the installed header files do not depend on
the macro and always match the installed library.

This patch also adds a missing RPM dependency on zchunk-devel to
librepo-devel if built with enabled zchunk. (Some header files include
<zck.h>.)

An implementation note: CMakeLists.txt appends the header search paths
with both a top-level build directory as well as with a librepo
subdirectory. The latter is for "util.h" inclusions from the C files,
the former is for <librepo/util.h> inclusions from other librepo header
files. Without the former a C preprocesor would use already installed
<librepo/util.h>. We do not want to infect the being built library
with old and possible nonmatching system header files.

Fixes: rpm-software-management#298
kontura pushed a commit that referenced this issue Mar 7, 2024
If librepo was built with -DWITH_ZCHUNK=ON but an application included
<librepo/librepo.h> without defining -DWITH_ZCHUNK, struct
LrDownloadTarget mismatched. The same problem happened vice versa.
Following the correct ABI was a burden for librepo applications and
a mistake there could lead to a memory corruption.

This patch replaces the WITH_ZCHUNK macros in the public header files
with a constant so that the installed header files do not depend on
the macro and always match the installed library.

This patch also adds a missing RPM dependency on zchunk-devel to
librepo-devel if built with enabled zchunk. (Some header files include
<zck.h>.)

An implementation note: CMakeLists.txt appends the header search paths
with both a top-level build directory as well as with a librepo
subdirectory. The latter is for "util.h" inclusions from the C files,
the former is for <librepo/util.h> inclusions from other librepo header
files. Without the former a C preprocesor would use already installed
<librepo/util.h>. We do not want to infect the being built library
with old and possible nonmatching system header files.

Fixes: #298
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 a pull request may close this issue.

1 participant