Skip to content

Commit

Permalink
Merge pull request #22 from boli1024/master
Browse files Browse the repository at this point in the history
support UTF-8 file name
  • Loading branch information
cdarras authored Nov 14, 2023
2 parents 53273f8 + 6c0e137 commit ced9490
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build:
Expand All @@ -21,3 +22,16 @@ jobs:
cache: maven
- name: Build with Maven
run: mvn -B verify --file pom.xml

- name: package
run: mvn clean package

- name: Create GitHub release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: 2.1.3-SNAPSHOT
title: 2.1.3-SNAPSHOT
prerelease: false
files: target/clamav-client-2.1.3-SNAPSHOT.jar

27 changes: 16 additions & 11 deletions src/main/kotlin/xyz/capybara/clamav/commands/Command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,26 @@ internal abstract class Command<out T> {
protected abstract val format: CommandFormat

protected open val rawCommand: ByteBuffer
get() = ByteBuffer.wrap("${format.prefix}$commandString${format.terminator}".toByteArray(StandardCharsets.US_ASCII))
get() = ByteBuffer.wrap("${format.prefix}$commandString${format.terminator}".toByteArray(StandardCharsets.UTF_8))

@Throws(IOException::class)
protected fun readResponse(socketChannel: SocketChannel): T {
val responseStringBuilder = StringBuilder()
var rawResponsePart = ByteBuffer.allocate(32)
var read = socketChannel.read(rawResponsePart)
while (read > -1) {
var rawResponsePartString = String(rawResponsePart.array(), StandardCharsets.US_ASCII)
rawResponsePartString = rawResponsePartString.substring(0, read)
responseStringBuilder.append(rawResponsePartString)
rawResponsePart = ByteBuffer.allocate(32)
read = socketChannel.read(rawResponsePart)
var readByteBuffer = ByteBuffer.allocate(32)
var responseByteArray = ByteArray(0)

var readSize = socketChannel.read(readByteBuffer)
while (readSize > -1) {
var readByteArray = readByteBuffer.array()
if (readSize < 32) {
readByteArray = readByteArray.sliceArray(0 until readSize)
}
responseByteArray = responseByteArray.plus(readByteArray)

readByteBuffer = ByteBuffer.allocate(32)
readSize = socketChannel.read(readByteBuffer)
}
val responseString = removeResponseTerminator(responseStringBuilder.toString())

val responseString = removeResponseTerminator(responseByteArray.decodeToString())
if (responseString == "UNKNOWN COMMAND") {
throw UnknownCommandException(commandString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ internal class ContScan(private val path: String) : ScanCommand() {
get() = CommandFormat.NEW_LINE

override val rawCommand: ByteBuffer
get() = ByteBuffer.wrap("${format.prefix}$commandString $path${format.terminator}".toByteArray(StandardCharsets.US_ASCII))
get() = ByteBuffer.wrap("${format.prefix}$commandString $path${format.terminator}".toByteArray(StandardCharsets.UTF_8))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ internal class MultiScan(private val path: String) : ScanCommand() {
get() = CommandFormat.NEW_LINE

override val rawCommand: ByteBuffer
get() = ByteBuffer.wrap("${format.prefix}$commandString $path${format.terminator}".toByteArray(StandardCharsets.US_ASCII))
get() = ByteBuffer.wrap("${format.prefix}$commandString $path${format.terminator}".toByteArray(StandardCharsets.UTF_8))
}
2 changes: 1 addition & 1 deletion src/main/kotlin/xyz/capybara/clamav/commands/scan/Scan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ internal class Scan(private val path: String) : ScanCommand() {
get() = CommandFormat.NULL_CHAR

override val rawCommand: ByteBuffer
get() = ByteBuffer.wrap("${format.prefix}$commandString $path${format.terminator}".toByteArray(StandardCharsets.US_ASCII))
get() = ByteBuffer.wrap("${format.prefix}$commandString $path${format.terminator}".toByteArray(StandardCharsets.UTF_8))
}

0 comments on commit ced9490

Please sign in to comment.