RationalTime::from_time_string rejects any time string with a leading '-', including the output of to_time_string
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
Línea de trabajo
El bucle de análisis es from_time_string en src/opentime/rationalTime.cpp (alrededor de las líneas 395-410). Léelo contra el contrato documentado en rationalTime.h, líneas 214-218, y revisa to_time_string para ver las cadenas negativas exactas que emite. Compila el target opentime con CMake y ejecuta el programa de reproducción del issue. Después, añade casos a tests/test_opentime.py (test_time_time_string_negative_rational_time) y a las pruebas C++ de opentime. Está terminado cuando -01:00:00, -10 y -00:00:01.0 se analizan como los segundos negativos esperados y hacen el round trip.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Required:
[x] I believe this isn't a duplicate topic
[x] This report is not related to an adapter
Select One:
[ ] Build problem
[x] Incorrect Functionality or bug
[ ] New feature or functionality
Description
RationalTime::from_time_string() returns INVALID_TIME_STRING for every string that starts with a minus sign, for example "-01:00:00", "-10" or "-00:00:01.0".
The header says a leading minus is allowed (rationalTime.h, lines 214-218):
/// @brief Parse a string in the form "hours:minutes:seconds".
///
/// The string may have a leading negative sign.
to_time_string() produces such strings for negative times (since #605), and the Python test test_time_time_string_negative_rational_time checks that RationalTime(-24, 24) gives "-00:00:01.0". Passing that exact string back to from_time_string() fails, so a negative time cannot make a round trip through a time string.
Expected: from_time_string("-01:00:00", 24) returns -3600 seconds (value -86400 at rate 24) with no error, and from_time_string("-00:00:01.0", 24) returns -1 second, like RationalTime(-24, 24).
Suggestion for the cause: in the backward scan of from_time_string (rationalTime.cpp, lines 395-404), the branch that rejects non-digit characters also runs when current reaches the leading '-', before the start == current branch (line 406) can call parseFloat(..., true, ...) with negatives allowed. Even past that point, the sign would only apply to the hours field ("-00:00:01.0" would give +1 s), so it may be simpler to strip a leading '-' first and negate the total at the end.
Reproduction Steps
Build against the C++ library (opentime) and run:
#include <opentime/errorStatus.h>
#include <opentime/rationalTime.h>
#include <cstdio>
#include <string>
using namespace opentime::OPENTIME_VERSION_NS;
static int failures = 0;
static void check(
const char* label,
const std::string& input,
double rate,
double expected_seconds)
{
ErrorStatus es;
RationalTime rt = RationalTime::from_time_string(input, rate, &es);
const bool err = is_error(es);
printf(
"%s: input=\"%s\" rate=%g -> error=%s code=%d valid=%d value=%g "
"rate=%g to_seconds=%.6f\n",
label,
input.c_str(),
rate,
err ? "yes" : "no",
(int) es.outcome,
(int) rt.is_valid_time(),
rt.value(),
rt.rate(),
rt.to_seconds());
if (err)
{
printf(
"FAIL %s: \"%s\" rejected (outcome=%d details=\"%s\"); header "
"says \"The string may have a leading negative sign\", expected "
"to_seconds=%.6f\n",
label,
input.c_str(),
(int) es.outcome,
es.details.c_str(),
expected_seconds);
++failures;
return;
}
if (rt.to_seconds() != expected_seconds)
{
printf(
"FAIL %s: parsed to_seconds=%.6f, expected %.6f\n",
label,
rt.to_seconds(),
expected_seconds);
++failures;
}
}
int main()
{
// positive control
{
ErrorStatus es;
RationalTime rt = RationalTime::from_time_string("01:00:00", 24, &es);
printf(
"control positive: error=%s to_seconds=%.6f\n",
is_error(es) ? "yes" : "no",
rt.to_seconds());
if (is_error(es) || rt.to_seconds() != 3600.0)
{
printf("FAIL control: positive string did not parse\n");
++failures;
}
}
// leading negative sign
check("minus-hhmmss", "-01:00:00", 24, -3600.0);
check("minus-hhmmss-frac", "-01:00:00.0", 24, -3600.0);
check("minus-min", "-1:00:00", 24, -3600.0);
check("minus-seconds-only", "-10", 24, -10.0);
// round trip through to_time_string() / from_time_string()
{
RationalTime rt(-24, 24);
std::string ts = rt.to_time_string();
printf("to_time_string(RationalTime(-24,24)) = \"%s\"\n", ts.c_str());
check("roundtrip-neg-1s", ts, 24, -1.0);
}
{
RationalTime rt(-3600, 1);
std::string ts = rt.to_time_string();
printf("to_time_string(RationalTime(-3600,1)) = \"%s\"\n", ts.c_str());
check("roundtrip-neg-1h", ts, 24, -3600.0);
}
if (failures)
{
return 1;
}
printf("all negative time strings parsed as documented\n");
return 0;
}
Log output if appropriate
Observed:
control positive: error=no to_seconds=3600.000000
minus-hhmmss: input="-01:00:00" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-hhmmss: "-01:00:00" rejected (outcome=3 details="Error: '-01:00:00' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000
minus-hhmmss-frac: input="-01:00:00.0" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-hhmmss-frac: "-01:00:00.0" rejected (outcome=3 details="Error: '-01:00:00.0' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000
minus-min: input="-1:00:00" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-min: "-1:00:00" rejected (outcome=3 details="Error: '-1:00:00' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000
minus-seconds-only: input="-10" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL minus-seconds-only: "-10" rejected (outcome=3 details="Error: '-10' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-10.000000
to_time_string(RationalTime(-24,24)) = "-00:00:01.0"
roundtrip-neg-1s: input="-00:00:01.0" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL roundtrip-neg-1s: "-00:00:01.0" rejected (outcome=3 details="Error: '-00:00:01.0' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-1.000000
to_time_string(RationalTime(-3600,1)) = "-01:00:00.0"
roundtrip-neg-1h: input="-01:00:00.0" rate=24 -> error=yes code=3 valid=0 value=0 rate=-1 to_seconds=0.000000
FAIL roundtrip-neg-1h: "-01:00:00.0" rejected (outcome=3 details="Error: '-01:00:00.0' - invalid time string"); header says "The string may have a leading negative sign", expected to_seconds=-3600.000000
Expected: no FAIL line. Every negative string is accepted with no error and gives -3600 s, -3600 s, -3600 s, -10 s, -1 s and -3600 s respectively, and the program prints all negative time strings parsed as documented.
Optional
Environment
OpenTimelineIO main at bad7ab5a40ac1a95d9d78a87c95a688d8b57cf28, and run again at f6c34bc6c3337cdd27db77c983c6074130c1c91c (20 Nov 2026) with the same result, C++ library opentime.
Operating System: Windows, MSVC (Visual Studio 2022 Build Tools), the project's CMake build in Debug configuration with AddressSanitizer (/fsanitize=address).
Python version if appropriate: n/a (C++ API; the same function is exposed as otio.opentime.from_time_string).
Found by VaultLens, an analysis tool that uses AI to catch bugs. If anything is wrong, please let us know.
- Lenguaje dominante
- C++
- Estrellas
- 2.1k
- Forks
- 367
- Merge medio
- 3 d 22 h
- PR fusionados (30 d)
- 14
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de AcademySoftwareFoundation/OpenTimelineIO
-
RationalTime::to_time_string gives a malformed or wrong string when the fractional second is below 0.0001Posiblemente ocupada @SoulmatelynchVFX la tomó hace 4 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
AcademySoftwareFoundation/OpenTimelineIO#2107 ·
Los mantenedores suelen responder en 1 día
-
otio_imath.cpp fails to compile with the latest Imath/pybind11Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
AcademySoftwareFoundation/OpenTimelineIO#2037 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
AcademySoftwareFoundation/OpenTimelineIO#2108 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
AcademySoftwareFoundation/OpenTimelineIO#2098 ·
Los mantenedores suelen responder en 1 día
-
Rust bindings?Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
AcademySoftwareFoundation/OpenTimelineIO#2093 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de AcademySoftwareFoundation/OpenTimelineIO
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
godotengine/godot#125913 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
期待增加虚线线条样式Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 94/100
vllm-project/vllm#70568 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mw00/project-maya#1368 ·
Los mantenedores suelen responder en 2 días