-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't assume EOF on 0-length read for Node
Remove the special handling code that detects EOF now that the upstream crate has fixed the bug that was being worked around. This also fixes a bug where EOF was being incorrectly detected when the provided buffer was empty. Add a test case to prevent regression in the future.
- Loading branch information
1 parent
2feac34
commit c6857dd
Showing
9 changed files
with
116 additions
and
17 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
java/client/src/test/java/org/signal/libsignal/media/InputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Copyright 2024 Signal Messenger, LLC. | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// | ||
|
||
package org.signal.libsignal.media; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import org.junit.Test; | ||
import org.signal.libsignal.internal.Native; | ||
|
||
public class InputStreamTest { | ||
|
||
@Test | ||
public void testReadIntoEmptyBuffer() { | ||
byte[] data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes(); | ||
assertArrayEquals( | ||
Native.TESTING_InputStreamReadIntoZeroLengthSlice(new ByteArrayInputStream(data)), data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Copyright 2024 Signal Messenger, LLC. | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// | ||
|
||
import { assert, use } from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
|
||
import * as Native from '../../Native'; | ||
import { Uint8ArrayInputStream } from './ioutil'; | ||
|
||
use(chaiAsPromised); | ||
|
||
const CAPS_ALPHABET_INPUT = Buffer.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); | ||
|
||
describe('InputStream', () => { | ||
it('handles reads into empty buffers', async () => { | ||
const input = new Uint8ArrayInputStream(CAPS_ALPHABET_INPUT); | ||
const output = await Native.TESTING_InputStreamReadIntoZeroLengthSlice( | ||
input | ||
); | ||
assert.deepEqual(output.compare(CAPS_ALPHABET_INPUT), 0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Copyright 2024 Signal Messenger, LLC. | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// | ||
|
||
@testable import LibSignalClient | ||
@testable import SignalFfi | ||
import XCTest | ||
|
||
class IoTests: TestCaseBase { | ||
func testReadIntoEmptyBuffer() throws { | ||
let input = [UInt8]("ABCDEFGHIJKLMNOPQRSTUVWXYZ".utf8) | ||
let inputStream = SignalInputStreamAdapter(input) | ||
let output = try withInputStream(inputStream) { input in | ||
try invokeFnReturningArray { output in | ||
SignalFfi.signal_testing_input_stream_read_into_zero_length_slice(output, input) | ||
} | ||
} | ||
XCTAssertEqual(input, output) | ||
} | ||
} |