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

Optional argument "source_path" ignored by build_fuzzers #7634

Closed
rlohning opened this issue Apr 27, 2022 · 1 comment · Fixed by #8734
Closed

Optional argument "source_path" ignored by build_fuzzers #7634

rlohning opened this issue Apr 27, 2022 · 1 comment · Fixed by #8734

Comments

@rlohning
Copy link
Contributor

The help text shown when calling
python infra/helper.py build_fuzzers
without further arguments reads that an optional argument "source_path" can be passed. Some months ago, this used to build sources from that path instead of those in the Dockerfile.

When I try it now, this argument seems to be ignored and the fuzzers are always being build from the Dockerfile. Am I missing something? It looks to me like either build_fuzzers has a bug or the help text is outdated.

@DavidKorczynski
Copy link
Collaborator

DavidKorczynski commented May 4, 2022

Is this related to the qt project? I think it might be because of this commit: a0b3dc9 where the destination folder of the project being cloned switched from qt to qt5, and all of the source code used to be in the /src/qt folder but is now spread out across several folders instead.

The code for source_path is a bit hacky in that it relies on matching lines in the Dockerfile with project names, see e.g.:

oss-fuzz/infra/helper.py

Lines 507 to 528 in 5a889cf

def workdir_from_lines(lines, default='/src'):
"""Gets the WORKDIR from the given lines."""
for line in reversed(lines): # reversed to get last WORKDIR.
match = re.match(WORKDIR_REGEX, line)
if match:
workdir = match.group(1)
workdir = workdir.replace('$SRC', '/src')
if not os.path.isabs(workdir):
workdir = os.path.join('/src', workdir)
return os.path.normpath(workdir)
return default
def _workdir_from_dockerfile(project):
"""Parses WORKDIR from the Dockerfile for the given project."""
with open(project.dockerfile_path) as file_handle:
lines = file_handle.readlines()
return workdir_from_lines(lines, default=os.path.join('/src', project.name))

The specific code that adds the logic to the docker command is

oss-fuzz/infra/helper.py

Lines 656 to 669 in 5a889cf

workdir = _workdir_from_dockerfile(project)
if mount_path:
command += [
'-v',
'%s:%s' % (_get_absolute_path(source_path), mount_path),
]
else:
if workdir == '/src':
logging.error('Cannot use local checkout with "WORKDIR: /src".')
return False
command += [
'-v',
'%s:%s' % (_get_absolute_path(source_path), workdir),

In the case of qt the identified workdir returned from _workdir_from_dockerfile is /src/qt which means when building the fuzzers the following is added to the Docker command: -v source_path_provided:/src/qt. As such, since the aforementioned commit has changed the locations of the source files in the Docker image (from qt to various subfolders?) then the content of the source path you provided is not used.

One way to solve this is to place all source code in the Dockefile inside of e.g. $SRC/qt/ again, and then that should work.

qtprojectorg pushed a commit to qt/qtqa that referenced this issue Oct 6, 2022
The way the oss-fuzz Dockerfile is currently defined does not allow for
the use of a local checkout of Qt when building the fuzzers or the test
cases.

In order to fix that, the first step is to update this script so it is
ready for the new version of the Dockerfile but also keep it compatible
with the current version so that there's no break on the fuzzing side
until the new Dockerfile is merged by the oss-fuzz project.

Related: google/oss-fuzz#7634

Change-Id: I98bfa4a3d83d1a3259eb4b7a33e839ededc54751
Reviewed-by: Robert Löhning <robert.loehning@qt.io>
sgaist added a commit to sgaist/oss-fuzz that referenced this issue Oct 10, 2022
This way the clones will follow the same structure
as the Qt sources and it will possible to mount
them again to test fixes.

To be merged after this patch goes in:
https://codereview.qt-project.org/c/qt/qtqa/+/423444

Fixes google#7634
Navidem pushed a commit that referenced this issue Oct 10, 2022
The current Docker image as it is created does not allow the use of
external sources to test fixes as the mount will come on top of all the
SRC content which has more than just the Qt sources.

This patch changes that and moves the clone to a dedicated folder so it
will follow the same structure as the Qt sources and it will possible to
mount them again to test fixes.

Fixes #7634
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.

2 participants