False Negative: CloseWriter.ql misses leaked wrapped streams when the close is skipped by an early return or hidden in a factory.
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 52/100
Direção de pesquisa
Comece lendo Likely Bugs/Resource Leaks/CloseWriter.ql e inspecione os casos afetados em PosCase2_Var3.java e PosCase2_Var5.java. Rastreie como a consulta lida com retornos antecipados e streams criados por helpers e, em seguida, execute os testes relevantes de CloseWriter. Está concluído quando ambos os casos forem reportados como leaks sem quebrar a cobertura existente.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Resource Leaks/CloseWriter.ql - Checker description: This checker detects instances where a Writer or OutputStream is created but not guaranteed to be closed on method exit, potentially causing resource leaks.
Description of the false negative
Both examples still leak the underlying file stream. One exits the method before the wrapper is closed. The other moves stream construction into a helper and then never closes the returned wrapper.
Those are ordinary resource-leak scenarios. Neither refactoring changes the ownership or lifetime of the stream.
Affected test cases
PosCase2_Var3.java
The return bypasses the only close() call. bos and the wrapped FileOutputStream both remain unclosed on the live path.
// FileOutputStream passed to BufferedOutputStream where inner resource not guaranteed to be closed should be flagged.
package scensct.var.pos;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class PosCase2_Var3 {
public void writeBuffered() throws IOException {
// Variant 3: Introduce early return that skips close
FileOutputStream fos = new FileOutputStream("data.bin");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(1);
if (System.currentTimeMillis() > 0) {
return; // exit without closing
}
// Unreachable code, close never called
bos.close();
}
}
PosCase2_Var5.java
The factory method only hides allocation. It does not transfer cleanup responsibility anywhere else, and the caller still never closes the returned stream.
// FileOutputStream passed to BufferedOutputStream where inner resource not guaranteed to be closed should be flagged.
package scensct.var.pos;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class PosCase2_Var5 {
public void writeBuffered() throws IOException {
// Variant 5: Wrap in a method that returns the BufferedOutputStream without closing
BufferedOutputStream bos = openBufferedStream("data.bin");
bos.write(1);
// Not closed
}
private BufferedOutputStream openBufferedStream(String file) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
return new BufferedOutputStream(fos);
}
}
Cause analysis
Likely Bugs/Resource Leaks/CloseWriter.ql looks too dependent on one direct construction-and-close pattern. As soon as the leak is expressed through an early return or a helper that returns the wrapper, the result disappears.
That is too brittle for a resource-leak query. In real code, stream creation is often factored into small helpers, and missing close calls frequently happen on short-circuit exits.
- Linguagem predominante
- CodeQL
- Estrelas
- 10.1k
- Forks
- 2.1k
- Merge médio
- 2d 16h
- PRs com merge (30d)
- 143
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de github/codeql
-
agentic-workflows
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
false-positive javascript
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
false-positive
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Todas as issues de github/codeql
Issues semelhantes
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
canonical/paas-charm#368 · 1 comentário ·
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
palladius/rails8-app-on-gcp#142 ·
-
addition to tracking list Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
StevenBlack/hosts#3256 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
corsairdev/corsair#1764 ·
-
oblt-aw/detector/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100