Skip to content

Commit

Permalink
ID3FrameStringContentParser crash fix (#100)
Browse files Browse the repository at this point in the history
* added count check

* stringContentParser test for too small data

* swiftlint fixes

* swiftlint build phase refactoring
  • Loading branch information
Scytalion authored Apr 19, 2023
1 parent 87242fc commit b775b16
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 28 deletions.
120 changes: 92 additions & 28 deletions ID3TagEditor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 48;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -1022,6 +1022,7 @@
5FAF8DA621CED8600049798C /* example-v4-additional-data.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "example-v4-additional-data.mp3"; sourceTree = "<group>"; };
5FAF8DAE21CED92F0049798C /* MockSynchsafeEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSynchsafeEncoder.swift; sourceTree = "<group>"; };
6AE2D8AE296CBB3500CEE5DF /* Mp3FileReaderFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mp3FileReaderFactory.swift; sourceTree = "<group>"; };
7CB91E4829EF2F75000A452C /* RunSwiftlint.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = RunSwiftlint.sh; sourceTree = "<group>"; };
C506700658BCCA8D6CD0E270 /* MockFrameContentSizeCalculator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockFrameContentSizeCalculator.swift; sourceTree = "<group>"; };
C506701F77DD635B85857590 /* MockID3FrameCreatorsChain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockID3FrameCreatorsChain.swift; sourceTree = "<group>"; };
C5067081F30C2572649940F5 /* ID3FrameConfigurationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ID3FrameConfigurationTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1134,6 +1135,7 @@
45D4C39C25399ABD00501417 /* .gitignore */,
45D4C39B25399ABD00501417 /* .swiftlint.yml */,
45925B9A253B5277001C8D4F /* codecov.yml */,
7CB91E4829EF2F75000A452C /* RunSwiftlint.sh */,
45F03F8E258E3E9800BB3869 /* Scripts */,
45C286BF24C8CBBB00171A88 /* workflows */,
452831C72044C40700458375 /* Source */,
Expand Down Expand Up @@ -1577,7 +1579,7 @@
452831C12044C40700458375 /* Frameworks */,
452831C22044C40700458375 /* Headers */,
452831C32044C40700458375 /* Resources */,
45D4C38F2539977B00501417 /* ShellScript */,
45D4C38F2539977B00501417 /* Run swiftlint */,
);
buildRules = (
);
Expand Down Expand Up @@ -1614,7 +1616,7 @@
452831E12044C4F500458375 /* Frameworks */,
452831E22044C4F500458375 /* Headers */,
452831E32044C4F500458375 /* Resources */,
45D4C390253997A300501417 /* ShellScript */,
45D4C390253997A300501417 /* Run swiftlint */,
);
buildRules = (
);
Expand Down Expand Up @@ -1651,7 +1653,7 @@
45541B7320598F6C0025A8BF /* Frameworks */,
45541B7420598F6C0025A8BF /* Headers */,
45541B7520598F6C0025A8BF /* Resources */,
45D4C391253997B200501417 /* ShellScript */,
45D4C391253997B200501417 /* Run swiftlint */,
);
buildRules = (
);
Expand Down Expand Up @@ -1688,7 +1690,7 @@
45F833DF205904680046C804 /* Frameworks */,
45F833E0205904680046C804 /* Headers */,
45F833E1205904680046C804 /* Resources */,
45D4C392253997BA00501417 /* ShellScript */,
45D4C392253997BA00501417 /* Run swiftlint */,
);
buildRules = (
);
Expand Down Expand Up @@ -1907,7 +1909,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
45D4C38F2539977B00501417 /* ShellScript */ = {
45D4C38F2539977B00501417 /* Run swiftlint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -1916,32 +1918,35 @@
);
inputPaths = (
);
name = "Run swiftlint";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
shellScript = "$SRCROOT/RunSwiftlint.sh\n";
};
45D4C390253997A300501417 /* ShellScript */ = {
45D4C390253997A300501417 /* Run swiftlint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run swiftlint";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
shellScript = "$SRCROOT/RunSwiftlint.sh\n";
};
45D4C391253997B200501417 /* ShellScript */ = {
45D4C391253997B200501417 /* Run swiftlint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -1950,15 +1955,16 @@
);
inputPaths = (
);
name = "Run swiftlint";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
shellScript = "$SRCROOT/RunSwiftlint.sh\n";
};
45D4C392253997BA00501417 /* ShellScript */ = {
45D4C392253997BA00501417 /* Run swiftlint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -1967,13 +1973,14 @@
);
inputPaths = (
);
name = "Run swiftlint";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
shellScript = "$SRCROOT/RunSwiftlint.sh\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -2842,7 +2849,8 @@
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -2865,7 +2873,11 @@
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand All @@ -2892,7 +2904,11 @@
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand All @@ -2911,7 +2927,11 @@
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = Y682K92RZU;
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditorTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -2928,7 +2948,11 @@
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = Y682K92RZU;
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditorTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -2951,7 +2975,11 @@
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand Down Expand Up @@ -2981,7 +3009,11 @@
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand All @@ -3006,7 +3038,11 @@
DEVELOPMENT_TEAM = Y682K92RZU;
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "it.chicio.ID3TagEditor-iOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -3028,7 +3064,11 @@
DEVELOPMENT_TEAM = Y682K92RZU;
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "it.chicio.ID3TagEditor-iOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -3052,7 +3092,11 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand All @@ -3078,7 +3122,11 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand All @@ -3100,7 +3148,11 @@
COMPRESS_PNG_FILES = NO;
DEVELOPMENT_TEAM = Y682K92RZU;
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "it.chicio.ID3TagEditor-tvOS-tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
Expand All @@ -3119,7 +3171,11 @@
COMPRESS_PNG_FILES = NO;
DEVELOPMENT_TEAM = Y682K92RZU;
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "it.chicio.ID3TagEditor-tvOS-tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
Expand All @@ -3144,7 +3200,11 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand All @@ -3170,7 +3230,11 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 4.1.3;
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditor;
PRODUCT_NAME = ID3TagEditor;
Expand Down
12 changes: 12 additions & 0 deletions RunSwiftlint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if [[ "$(uname -m)" == arm64 ]]; then
export PATH="/opt/homebrew/bin:$PATH"
fi

# Type a script or drag a script file from your workspace to insert its path.
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
3 changes: 3 additions & 0 deletions Source/Parse/ID3FrameStringContentParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class ID3FrameStringContentParser {
func parse(frame: Data, version: ID3Version) -> String? {
let headerSize = id3FrameConfiguration.headerSizeFor(version: version)
let frameContentRangeStart = headerSize + id3FrameConfiguration.encodingSize()

guard frameContentRangeStart < frame.count else { return nil }

let frameContent = frame.subdata(in: frameContentRangeStart..<frame.count)
let encoding = stringEncodingDetector.detect(frame: frame, version: version)
if let frameContentAsString = String(data: frameContent, encoding: encoding) {
Expand Down
5 changes: 5 additions & 0 deletions Tests/Parse/ID3StringContentParsingOperationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ID3StringContentParsingOperationTest: XCTestCase {
id3FrameConfiguration: ID3FrameConfiguration()
)

func testTooSmallDataValue() {
let value = stringContentParser.parse(frame: Data(capacity: 1), version: .version3)
XCTAssertNil(value)
}

func testFrameContentParsedV2() {
let expectation = XCTestExpectation(description: "content without padding")
let id3StringContentParsingOperation = ID3FrameStringContentParsingOperation(
Expand Down

0 comments on commit b775b16

Please sign in to comment.