Skip to content

[YAML] Don't validate Fill::Size after error #123280

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,9 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
std::string MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
IO &io, std::unique_ptr<ELFYAML::Chunk> &C) {
if (const auto *F = dyn_cast<ELFYAML::Fill>(C.get())) {
if (F->Pattern && F->Pattern->binary_size() != 0 && !F->Size)
// Can't check the `Size`, as it's required and may be left uninitialized by
// previous error.
if (!io.error() && F->Pattern && F->Pattern->binary_size() != 0 && !F->Size)
return "\"Size\" can't be 0 when \"Pattern\" is not empty";
return "";
}
Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/ObjectYAML/MachOYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
std::string
MappingTraits<MachOYAML::Section>::validate(IO &IO,
MachOYAML::Section &Section) {
if (Section.content && Section.size < Section.content->binary_size())
// Can't check the `size`, as it's required and may be left uninitialized by
// previous error.
if (!IO.error() && Section.content &&
Section.size < Section.content->binary_size())
return "Section size must be greater than or equal to the content size";
return "";
}
Expand Down
41 changes: 41 additions & 0 deletions llvm/test/ObjectYAML/MachO/section_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,44 @@ LoadCommands:
reserved2: 0x00000000
reserved3: 0x00000000
content: AA

## Case 4: Don't validate if size is missing.
# RUN: not yaml2obj --docnum=4 %s -o %t1 2>&1 | FileCheck %s --check-prefix=CASE4 --implicit-check-not=error:
# CASE4: error: missing required key 'size'
# CASE4: error: failed to parse YAML

--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 1
sizeofcmds: 232
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 232
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 392
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __data
segname: __DATA
addr: 0x0000000000000000
content: AA
offset: 0x00000188
align: 2
reloff: 0x00000000
nreloc: 0
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
5 changes: 3 additions & 2 deletions llvm/test/tools/yaml2obj/ELF/custom-fill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ Sections:
Pattern: "BB"

## Check that the "Size" field is mandatory.
# RUN: not yaml2obj --docnum=5 2>&1 %s | FileCheck %s --check-prefix=NOSIZE
# RUN: not yaml2obj --docnum=5 2>&1 %s | FileCheck %s --check-prefix=NOSIZE --implicit-check-not=error:

## NOSIZE: error: missing required key 'Size'
# NOSIZE: error: missing required key 'Size'
# NOSIZE: error: failed to parse YAML

--- !ELF
FileHeader:
Expand Down
Loading